I have a module written in Python. Now I want to import it into another script and a list of all the classes defined in this module. Therefore, I try:
>>> import my_module
>>> dir(my_module)
['BooleanField', 'CharField', 'DateTimeField', 'DecimalField', 'MyClass', 'MySecondClass', 'ForeignKeyField', 'HStoreField', 'IntegerField', 'JSONField', 'TextField', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'datetime', 'db', 'division', 'os', 'struct', 'uuid']
The only two classes that I defined in my_module are MyClassand MySecondClass, the rest of the things are all that I imported into my_module.
Now I want to somehow get a list of all the classes that are defined in my_module, without getting anything else. Is there a way to do this in Python?
source
share