我正在我的raspberrypi3上编写一个python脚本,它将从一个开源的scale记录权重并将它们放入数据库中。电子秤只是将输出/读数记录到一个文件中。问题是电子秤输出了很多我不需要的数据。每次脚本运行时,它都会在文件的底部添加一个新的读数,您可以看到下面的一部分。所以基本上我需要的是最新的重量读数,它总是在文件的最后一行。你知道吗
我对正则表达式有点不在行。尽管我一直在寻找和尝试,但我似乎无法将最后的体重读数分离出来。你知道吗
Serial Load Cell Converter version 1.2
By SparkFun Electronics
No remote sensor found
Minimum time between reports: 791
Press x to bring up settings
Readings:
1274,2.5007,lbs,540611,
Serial Load Cell Converter version 1.2
By SparkFun Electronics
No remote sensor found
Minimum time between reports: 792
Press x to bring up settings
Readings:
1341,2.5008,lbs,540620,
Serial Load Cell Converter version 1.2
By SparkFun Electronics
No remote sensor found
Minimum time between reports: 792
Press x to bring up settings
Readings:
1321,2.5009,lbs,540643,
最后一行: 1321,2.5009,磅,540643
我需要“2.5009”所在的值,但我不能简单地匹配这个数字,因为它会随着每个读数的增加而急剧变化,就像最后一行上的其他数字一样。唯一保持不变的是逗号和“lbs”。你知道吗
也许,这个表达式可以提取最后一个值:
测试
输出
相关问题 更多 >
编程相关推荐