[英]how to make script that run just once per day in python
I'm trying to make script that run functions just once per day (and I can not guarantee when exactly I will run the script) what I'm trying to do exactly is saving the second (y) variable's output instead on number 5 located in first (y) variable to later use我正在尝试制作每天只运行一次函数的脚本(我不能保证我将在什么时候运行该脚本)我想要做的是保存第二个(y)变量的 output 而不是位于 5 号在第一个 (y) 变量中供以后使用
import datetime
class daily():
y = 5
x = (datetime.datetime.today().day)
if x != y:
print("def")
def one():
print("one")
def two():
print("two")
y = (datetime.datetime.today().day)
elif x == y:
print("done")
pass
Ok.好的。
First you create a day.json
file.首先创建一个
day.json
文件。
content内容
{
"day": 5
}
This is an example这是一个例子
import datetime
import json
class daily:
y = json.load(open('day.json', 'r'))['day']
x = datetime.datetime.today().day
if x != y:
print("def")
def one(self):
print("one")
def two(self):
print("two")
y = {'day': datetime.datetime.today().day}
json.dump(y, open('day.json', 'w'), indent=2)
elif x == y:
print("done")
pass
I have not run this program, if there is an error, please let me know.我没有运行这个程序,如果有错误,请告诉我。
You can go to GOOGLE Python open
for related instructions.您可以 go 到 GOOGLE Python
open
相关说明。
In this example, I use .json
, you can also just use .txt
for access.在本例中,我使用
.json
,您也可以只使用.txt
进行访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.