module_to_dict.py 334 B

12345678
  1. # Based on: https://stackoverflow.com/a/46263657
  2. def module_to_dict(module):
  3. context = {}
  4. for name in dir(module):
  5. # this will filter out 'private' functions, as well as __builtins__, __name__, __package__, etc.:
  6. if not name.startswith('_'):
  7. context[name] = getattr(module, name)
  8. return context