1
我想檢查名爲component +「_STATUS」或+「_DESC」的變量是否存在。如何檢查變量是否存在?
我試過以下,但它不會工作。所以,這裏是我的代碼:
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)
就像一個魅力! :) – Marko
@Marko - 謝謝你)希望這會有所幫助 –