【发布时间】:2018-03-08 20:54:31
【问题描述】:
所以我一直在玩一些日程安排,我发现Schedule github 有日程安排,而且非常好用且易于使用。所以到目前为止我所做的是:
UserInput = input('To run Schedule script - Press y\nTo run directly - Press n\n')
if(UserInput == 'n'):
main()
elif(UserInput == 'y'):
TimeUser = input('What time to start script? Format - HH:MM ')
schedule.every().day.at(TimeUser).do(main)
wipe()
print('Schedule starts at: ' + TimeUser + ' - Waiting for time...')
while True:
schedule.run_pending()
time.sleep(1)
if(schedule.idle_seconds() == '5'):
print('Program starts in...:\n' + str(schedule.idle_seconds()) + '\n')
但是我现在遇到的问题是我的输出结果是
程序开始于...: 30.08442
Program starts in...:
29.083967
Program starts in...:
28.083956
Program starts in...:
27.083923
基本上我想做的是 if(schedule.idle_seconds()): 5 秒。因此,当它离开 5 秒时,它应该开始打印出来。然而,我遇到的问题是它永远不会达到 5 秒,因为我认为是毫秒。所以我想知道是否有办法修剪/剪切/格式化它,这样它会在剩下 5 秒时开始打印出来?
编辑输出:
--------------------------------------
Schedule starts at: 13:55 - Waiting for time...
--------------------------------------
Program starts in...:
4.748427
--------------------------------------
Wrong input - Try again
--------------------------------------
To run Schedule task - Press y
To run directly - Press n
【问题讨论】:
标签: python time format scheduled-tasks trim