2015年9月2日 星期三

pythonic way to check if something exists?

Easier to ask forgiveness than permission:
try:
  x
except NameError:
  x_exists = False
else:
  x_exists = True

reference : http://stackoverflow.com/questions/9390126/pythonic-way-to-check-if-something-exists

沒有留言:

張貼留言