'Exit If Statement
I'm confused and stucked when im trying to quit/ continue in if statement
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:
I want to check if quota is not 0 then continue for execution, but when quota equals to 0, I want it to stop at there. Anyone can help me?
Solution 1:[1]
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
Solution 2:[2]
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")
well i got it
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Tomalak |
Solution 2 | MorpKnight |