python 偵測變數是否存在
try:
a
except NameError:
a = 'xxx'
print a
如果a 本來就存在的話, a 就會是本來的值, 否則a 將會被賦與 'xxx' 的值
http://stackoverflow.com/questions/843277/how-do-i-check-if-a-variable-exists-in-python
http://bytes.com/topic/python/answers/21180-test-see-if-variable-exists
留言
張貼留言