I want to check if variables named component + “_STATUS” or + “_DESC” exist.
I tried the following, but it won’t work. So, here’s my code:
Components = ['SAVE_DOCUMENT', \
'GET_DOCUMENT', \
'DVK_SEND', \
'DVK_RECEIVE', \
'GET_USER_INFO', \
'NOTIFICATIONS', \
'ERROR_LOG', \
'SUMMARY_STATUS']
for Component in Components:
try:
eval(Component + "_STATUS")
eval(Component + "_DESC")
except NameError:
print "Missing component " + Component + " information!"
sys.exit(StateUnknown)
I might be wrong but i think that you can do this the following way(without usign eval – because it is not a very good to use it):
In case you need to check variable presence in local scope you can use locals(), otherwise you can use globals()