Answers for "python determine if a property is in a class"

5

python check if class has function

class A:
  def func():
    pass
hasattr(A(), 'func')
Posted by: Guest on July-03-2020
0

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
Posted by: Guest on May-11-2021

Code answers related to "python determine if a property is in a class"

Python Answers by Framework

Browse Popular Code Answers by Language