,所以我一直在玩日程,终于让它开始工作。我太兴奋了,无法肯定还有另一个问题哈哈。但是,现在的问题是,每当主完成后,它都不会结束,并且我真的找不到解决方案。我知道问题位于行 time.sleep(1)上我真的找不到结束它的灵魂。
im使用github的时间表:github时间表
while True:
UserInput = input('To run Schedule task - Press ynTo run directly - Press nn')
if(UserInput == 'y' or UserInput == 'Y'):
print(Fore.RESET + space)
TimeUser = input('What time to start script? Format - HH:MMn')
schedule.every().day.at(TimeUser).do(main)
wipe()
print('Schedule starts at: ''' + TimeUser + ' - Waiting for time...')
idle = int(round(schedule.idle_seconds()))
while True:
schedule.run_pending()
time.sleep(1)
idle = int(round(schedule.idle_seconds()))
if(idle < 6.0) and (idle >= 0.0):
print('Starting in: ' + str(idle))
elif(UserInput == 'n' or UserInput == 'N'):
main()
print("Wrong input - Try again")
您可以使用for
关键字。for语句可以定义您的迭代和停止条件。或使用range()
函数在数值序列上迭代。
被用于传统的如果是else语句,则break
语句将使您从循环中脱颖而出。它需要与您最内向的for
或while
环相处。您的else
子句需要属于您的for
循环,而不是if
语句的一部分。continue
语句将向前移动您的循环。
这里有示例:https://docs.python.org/3/tutorial/controlflow.html
您的代码以true
作为参数封装在while
循环中。您是错误地这样做的,或者这是结构差。这是问题。
如果您不想删除while
循环,则至少在某处添加break
。
如果您需要帮助构造代码的帮助,请转到代码评论。