[英]I am trying to pass a different argument to a function for every schedule such as the following,
import schedule
import time
arr = ['React', 'Python', 'JS', 'PHP', 'anything']
def add_no(key):
return print(key, ' got it')
for i, index in enumerate(arr):
schedule.every(3).seconds.do(add_no, index)
schedule.run_pending()
time.sleep(2)
print(i, ':', index)
我正在嘗試為每個計划將不同的參數傳遞給函數,如下所示:每個指定的時間段我想從 arr 傳遞一個參數並執行代碼,然后完成后,我將第二個參數傳遞給函數等等直到循環退出,就像每 3 分鍾我想將 str 作為參數傳遞給我的函數並執行等等:現在終端顯示,
0: React
1: Python
React got it
2: JS
Python got it
3: PHP
React got it
JS got it
4: anything
我想要的輸出是
0: React
React got it
1: Python
Python got it
2: JS
JS got it
3: PHP
PHP got it
JS got it
等等
也許你想要這樣的東西
import schedule
import time
arr = ['React', 'Python', 'JS', 'PHP', 'anything']
def add_no(key):
return print(key, ' got it')
for i, index in enumerate(arr):
schedule.every(3).seconds.do(add_no, index)
schedule.run_pending()
time.sleep(3)
print(i, ':', index)
0 : React
React got it
1 : Python
Python got it
React got it
2 : JS
JS got it
Python got it
React got it
3 : PHP
PHP got it
JS got it
Python got it
React got it
4 : anything
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.