'Try Catch missing variables in Python
I am building a python code that takes inputs from other source which I can not control.
That source sends some variables, but if some variables are missing then it does not send them at all.
Case 1: VariableName = 5
Case 2:
In my Python code I then do the following to make sure that I do not get error when I try to use missing variables.
try: VariableName
except NameError: VariableName= 0
else: VariableName=VariableName
Now, if I have 100 of these variables, how can I avoid writing this try catch statement multiple times? I can not think of a way to write it in some function or loop because all of these solutions first evaluate the variable and then go to try catch and this will throw an error if my variable does not exist.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
