我正在尝试将一些python脚本安排在并在中运行main.py
。这些脚本放在同一文件夹中。
main.py
:
import schedule
import time
from test1 import dd
schedule.every(2).seconds.do(dd,fname)
while True:
schedule.run_pending()
time.sleep(1)
test1.py
:
def dd(fname):
print('hello' + fname)
dd('Mary')
dd('John')
它用那两个名字和结尾name 'fname' is not defined
。
如何在main.py
文件中定义参数?如果def
脚本中有多个脚本,是否需要在中导入,main.py
并且我在顶部导入的脚本要多次导入main.py
,因此在运行计划之前,该脚本要运行一次?这意味着它在导入时会运行一个?
您没有在main.py中定义您的fname,所以它说name 'fname' is not defined
。您只是将功能从test1.py导入到main.py中
这是修改后的代码:
main.py
import schedule
import time
from test1 import dd
fname="Mary"
schedule.every(2).seconds.do(dd,fname)
while True:
schedule.run_pending()
time.sleep(1)
test1.py
def dd(fname):
print('hello' + fname)
这些代码已使用Python 3.7.7进行了测试
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句