如何看代码,以下脚本只在06.30h和8.00h之间运行? 最好的问候
#!/usr/bin/python
from time import strftime
import sys
import subprocess from subprocess
import Popen
import pifacedigitalio
from time import sleep
pfd = pifacedigitalio.PiFaceDigital() # creates a PiFace Digital
object testprocess = None
while strftime('%H:%M') >= '06:29':
while(True):
sleep(0.1)
if pfd.input_pins[0].value == 1 and not testprocess:
subprocess.Popen(["/bin/myscript"])
testprocess = Popen(["/bin/myscript1"])
if pfd.input_pins[0].value == 0:
if testprocess:
testprocess.kill()
testprocess = None
subprocess.Popen(["/bin/mycript"])
sleep(1)
if strftime('%H:%M') == '08:00':
sys.exit()
答案 0 :(得分:2)
我会这样做:
This is my overridden greeting message
This shape is a Circle
您可以在此处详细了解时间模块:https://docs.python.org/2/library/time.html
答案 1 :(得分:0)
只需花时间进入时间结构并计算从午夜开始的分钟数,以分钟为单位测试时间窗口:
lt = time.localtime()
minutes = 60*lt.tm_hour + lt.tm_min
if 60*6+30 <= minutes <= 60*8:
subprocess.Popen(["/bin/myscript"])
testprocess = Popen(["/bin/myscript1"])