hasattr() is the Pythonic way to do it. Learn it, love it.
Other possible way is to check whether the variable name is in locals() or globals():
if varName in locals() or in globals():
do_something()
else:
do_something_else()
I personally hate to catch exceptions in order to check something. It looks and feels ugly. It's identical to checking if a string contains only digits that way:
s = "84984x"
try:
int(s)
do_something(s)
except ValueError:
do_something_else(s)
Instead of gently using s.isdigit(). Eww.