[Python] Python "isinstance" with class name instead of type

Discussão em 'Python' iniciado por Stack, Julho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I want to check if an object or variable is an instance of the specified class type, but using the name of this class, not its type. Something like this:

    class A: pass

    class B(A): pass

    class C(B): pass

    c_inst = C()

    # Not working, isinstance expects the type:
    ok = isinstance(c_inst, 'A')


    Are there any alternatives? I want to use the class name, so isinstance(c_inst, A) is not available in this case.

    Continue reading...

Compartilhe esta Página