How to pass a reference to the current module

Paul Rubin http
Sat Aug 4 06:21:26 EDT 2007


James Stroud <jstroud at mbi.ucla.edu> writes:
>     FunctionUser.do_something_with(globals(), 'doit', 7)

How about instead of "import FunctionUser", require

   from FunctionUser import do_something

In FunctionUser.py, write:

   frob = (some object that gets necessary stuff from module environment)

   def do_something(*user_args, __frob = frob): 
      # use __frob to access FunctionUser module contents as needed
      # ...
      (func, args) = getattr(FunctionUser, user_args[0]), user_args[1:]
      func(*args)



More information about the Python-list mailing list