Casebash
Casebash

Reputation: 118792

Python console - inspect classes or functions defined in a particular module

If you want to see what modules are defined in a particular module while in the Python shell, one option is to type dir(path.to.module). Unfortunately, this doesn't just list the classes or functions defined in a particular module, it also included classes or functions that the module imports

Upvotes: 1

Views: 54

Answers (1)

Casebash
Casebash

Reputation: 118792

The following function will only return functions and classes defined in a particular module

def getDefined(module):
    print([x for x in dir(module) if
        getattr(module.__dict__[x], '__module__','')==module.__name__
    ])

Upvotes: 1

Related Questions