[英]While Loop with time.sleep
我將使用while循環刷新方法。
def usagePerUserApi():
while True:
url = ....
resp = requests.get(url, headers=headers, verify=False)
data = json.loads(resp.content)
code = resp.status_code
Verbindungscheck.ausgabeVerbindungsCode(code)
head =.....
table = []
for item in (data['data']):
if item['un'] == tecNo:
table.append([
item['fud'],
item['un'],
str(item['lsn']),
str(item['fns']),
str(item['musage'])+"%",
str(item['hu']),
str(item['mu']),
str(item['hb']),
str(item['mb'])
])
print(tabulate(table,headers=head, tablefmt="github"))
time.sleep(300)
如果我這樣離開time.sleep,它將顯示為錯誤。 如果我將其置於while循環下,它將不斷更新,並且不會等待5分鍾。
我不知道錯誤在哪里。 我希望你能幫助我。
您需要導入python時間庫
如果你放
import time
在文件的頂部,它應該可以工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.