I’m trying to create a function that reloads a global bank
import json
type Bank = dict[str, dict[str: int | float]]
def get_ball() -> None:
"""
_summary_
Reloads the bank dict from the bank.json file
"""
global bank
with open("bank.json", "r") as f:
bank: Bank = json.load(f) #Error
print(bank)
get_ball()
print(bank)
But it raises a SyntaxError: annotated name ‘bank’ can’t be global
When it dont have asigned type it works just fine. What i have to do?
import json
type Bank = dict[str, dict[str: int | float]]
def get_ball() -> None:
"""
_summary_
Reloads the bank dict from the bank.json file
"""
global bank
with open("bank.json", "r") as f:
bank = json.load(f) #Works fine
print(bank)
get_ball()
print(bank)
New contributor
Patrovsky games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.