magic.py 400 B

123456789101112
  1. """Functions that involve magic. """
  2. def pollute(names, objects):
  3. """Pollute the global namespace with symbols -> objects mapping. """
  4. from inspect import currentframe
  5. frame = currentframe().f_back.f_back
  6. try:
  7. for name, obj in zip(names, objects):
  8. frame.f_globals[name] = obj
  9. finally:
  10. del frame # break cyclic dependencies as stated in inspect docs