python check if has attribute
if hasattr(a, 'property'):
a.property
python check if has attribute
if hasattr(a, 'property'):
a.property
python check if attribute exists in class
if hasattr(obj, 'propertyName'):
...
if object has property python
Use hasattr()
hasattr(object, name)
#The arguments are an object and a string.
#The result is True if the string is the name of one of the
#object’s attributes, False if not.
#(This is implemented by calling getattr(object, name) and
#seeing whether it raises an AttributeError or not.)
Docs: https://docs.python.org/3/library/functions.html#hasattr
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us