code_junkie

How can I dynamically get the set of classes from the current python module?

Nov 12th, 2011
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. class A(object):
  2. def __call__(self):
  3. print "ran a"
  4.  
  5. class B(object):
  6. def __call__(self):
  7. print "ran b"
  8.  
  9. class C(object):
  10. def __call__(self):
  11. print "ran c"
  12.  
  13. import sys
  14. getattr(sys.modules[__name__], 'A')
  15.  
  16. import sys
  17. import types
  18. this_module = sys.modules[__name__]
  19. [x for x in
  20. [getattr(this_module, x) for x in dir(this_module)]
  21. if type(x) == types.ClassType]
Add Comment
Please, Sign In to add comment