Importing to

James Stroud jstroud at mbi.ucla.edu
Thu Aug 9 20:27:36 EDT 2007


Many thanks to the numerous helpful comments by Paul Rubin, Carsten 
Haese and others in the thread "How to pass a reference to the current 
module".

After digesting these comments, I came up with this way to circumvent 
the problem of attempting to reference modules that import other modules 
  in said imported modules (executed in main):


   # branches ==> dictionary of dictionaries (actually a ConfigObj)
   for (name, branch) in branches.items():
     modname = branch.get('__module__', None)
     if modname is None:
       namespace = globals()
     else:
       namespace = __import__(modname).globals()
     fname = branch.get('__function__', name)
     function = namespace[fname]
     # etc.


I'm wondering if this approach seems problematic to anyone.

Thanks again for all of the help I've received.

James


-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list