How do you get all classes defined in a module but not imported?
Question: I've already seen the following question but it doesn't quite get me where I
want: [Python: Get list of all classes within current
module](http://stackoverflow.com/questions/1796180/python-get-list-of-all-
classes-within-current-module)

In particular, I do not want classes that are imported, e.g. if I had the
following module:

    
    
    from my.namespace import MyBaseClass
    from somewhere.else import SomeOtherClass
    
    class NewClass(MyBaseClass):
        pass
    
    class AnotherClass(MyBaseClass):
        pass
    
    class YetAnotherClass(MyBaseClass):
        pass
    

If I use `clsmembers = inspect.getmembers(sys.modules[__name__],
inspect.isclass)` like the accepted answer in the linked question suggests, it
would return `MyBaseClass` and `SomeOtherClass` in addition to the 3 defined
in this module.

How can I get only `NewClass`, `AnotherClass` and `YetAnotherClass`?


Answer: Inspect the `__module__` attribute of the class to find out which module it
was defined in.

