在特定时间之前运行Python程序 [英] Run Python Program Until Specific Time
本文介绍了在特定时间之前运行Python程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在jupyter笔记本中运行我的程序,并且该程序在特定时间(例如18:00)停止.我通过while循环和增量索引编写了程序,但是最好使用time参数来编写它.
I want to run my program in jupyter notebook and this program stops at specific time(for example 18:00). I wrote program by while loop and incremental index, but it's better to write it with time parameter.
我每天运行7个小时提到的程序.它必须不间断运行.
I run mentioned program for 7 hours each day. It must run nonstop.
while(i<500000):
execute algorithm
i+=1
但是我想像下面这样运行我的程序:
But I'd like to run my program like bellow:
while(not 18:00 clock):
execute algorithm
推荐答案
import datetime
while datetime.datetime.now().hour < 18:
do stuff...
或
if datetime.datetime.now().hour >= 18:
return
这篇关于在特定时间之前运行Python程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文