I've made a program that fetches data from an api and then uses some keys of it. It should return the keys, but if a certain key has no value- or is not in the data I want it to return that key with a 0.
So for example when looking up a certain player's karma (karma = r.json()["player"]["karma"]
) It will return a NoneType error as the value is empty. How can I make it set that value to 0, without writing a dozen for loops checking each one individually?
What I don't want (as there are a lot of keys):
try:
karma = r.json()["player"]["karma"]
except NoneType:
karma = 0