t1 = Tournament("Aeroflot Open", 2010)
json_data = json.dumps(t1.__dict__)
print(json_data)
t = Tournament(**json.loads(json_data)) # <-------------------
print(f"name = {t.name}, year = {t.year}")
Could someone explain me why do I need these two asterisks ** when loading the json back. The line is above.
In Python, there is unpacking of the iterator using * and unpacking of the dictionary using **.
Let's understand it with examples.
python will assign the key as a argument name and value as argument value like {"name": "IPL", "year": 13} the Tournament(name="IPL", year=13)
Either you can directly assign the data, like
For more understanding, follow this * and **