當我試圖退出/繼續 if 陳述句時,我感到困惑和卡住
def checkQuota():
with open("Discord\Test Field\config.json", "r ") as file:
data = json.load(file)
quota = data['guild setting']['daily quota']
if quota > 0:
我想檢查配額是否不為 0 然后繼續執行,但是當配額等于 0 時,我希望它停在那里。任何人都可以幫助我嗎?
uj5u.com熱心網友回復:
def checkQuota():
with open(r"Discord\Test Field\config.json", "r ") as file:
data = json.load(file)
quota = data['guild setting']['daily quota']
if quota == 0:
# out of quota
return
# ...rest of the function below
uj5u.com熱心網友回復:
def checkQuota():
with open("Discord\Test Field\config.json", "r ") as file:
data = json.load(file)
item = data['guild setting']['daily quota']
if item > 0:
quotaChange = item - 1
data['guild setting']['daily quota'] = quotaChange
file.seek(0)
json.dump(data, file, indent=4)
file.truncate()
else:
print("Today's quota is 0, can't process command")
好吧,我明白了
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/416345.html
標籤:
