Accessing global namespace from module

Reuben D. Budiardja techlist at pathfinder.phys.utk.edu
Tue Jun 12 17:37:45 EDT 2007


On Monday 11 June 2007 23:49:14 Gabriel Genellina wrote:
> En Mon, 11 Jun 2007 22:19:15 -0300, Reuben D. Budiardja
> > It'll be great if I can
> > put
> > this trick on a single file that is included by the main scripts, to
> > 
> According to your description on how things work, you will need the
> globals() from mainscript.py; try this:

> --- plot_setup.py ---
> import sys
>  from types import ModuleType as module
>
> def setup(namespace):
>      plotModule = module('plot')
>      for key,value in namespace.items():
>          if key[:2] != '__':
>              setattr(plotModule, key, value)
>      sys.modules['plot'] = plotModule
>

Hm.. apparently this works for function but doesn't work for method :(. Do you 
know of any reason ?

Thanks.
RDB
-- 
Reuben D. Budiardja
Dept. Physics and Astronomy



More information about the Python-list mailing list