[Python] How can I check if an object has an attribute?

Discussão em 'Python' iniciado por Stack, Abril 28, 2025.

  1. Stack

    Stack Membro Participativo

    How do I check if an object has some attribute? For example:

    >>> a = SomeClass()
    >>> a.property
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: SomeClass instance has no attribute 'property'


    How do I tell if a has the attribute property before using it?

    Continue reading...

Compartilhe esta Página