我试了一下:赶上但它不起作用.我想我可以把它改成if语句,但不明白为什么这不起作用.这是我的第一个"真实"项目.我正在建立一个灌溉控制器,并创建一个灌溉时间表字典.第一个是我到目前为止的代码,第二个代码是我正在尝试的"测试".每次我运行代码时,它都会重写现有文件,当我想要它时,如果它已经存在则打开文件而不是再次写入.
# timer will first look for a saved file(dictionary) of already recorded
# irrigation times. If no file exists it will create one.
# irrigation timer which does scheduled irrigation as well as cyclic irrigation for propagating plants.
# uses a lcd 1602 display
# will use up to 10 different valves
import time
import datetime
import threading
import RPi.GPIO as GPIO
from RPLCD import CharLCD # http://www.circuitbasics.com/raspberry-pi-lcd-set-up-and-programming-in-python/
GPIO.setmode(GPIO.BOARD)
# pinouts for lcd pins
lcd = CharLCD (cols=16, rows=2, …Run Code Online (Sandbox Code Playgroud)