class Foo: def spam(self): pass try: check = hasattr(Foo, 'eggs') except AttributeError: check = False print(check) print(hasattr(Foo, 'spam'))
I was misled by your AttributeError...
you don't need try/except
class Foo: def spam(self): pass check = hasattr(Foo, 'eggs') print(check) check = hasattr(Foo, 'spam') print(check)As a side note about using try/except - try should be before the line that may raise error, not after that.
try: print(1/0) except ZeroDivisionError: print('Cannot divide by 0')
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs