[Python] In Python, how do I get the list of classes defined within a particular file?

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

  1. Stack

    Stack Membro Participativo

    If a file myfile.py contains:

    class A(object):
    # Some implementation

    class B (object):
    # Some implementation


    How can I define a method so that, given myfile.py, it returns [A, B]?

    Here, the returned values for A and B can be either the name of the classes or the type of the classes.

    (i.e. type(A) = type(str) or type(A) = type(type))

    Continue reading...

Compartilhe esta Página