我使用的是一个使用python的程序,它用GPIO计算脉冲数并将它们存储在文本文件中。我想以这样一种方式更新程序:当程序重新启动或更新rapsberry pi时,计数器将继续从之前的最后一次计数开始计数。有人知道怎么做吗?谢谢。在
counter = 0
def my_callback2(channel)
global counter
counter = counter + 1
print counter
file = open("testfile.txt", "w")
file.write(str(counter))
file.close()
with open('testfile.txt', 'r') as f:
first_line = f.readline()
print "switch press detected"
必须有更简单的方法,但这可以做到:
注意:
some_file.txt
必须有一个有效的数字(0
也许?)第一次运行脚本时。在相关问题 更多 >
编程相关推荐