[Python-3000] A few small py3k wishes

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Apr 3 03:27:00 CEST 2006


Talin wrote:

> -- A mechanism whereby imported modules can import
> symbols from the module that imported them. (Specifically,
> I want to take a bunch of variables in my __main__ module
> and make them accessible to the imported module.)

In my_imported_module.py:

   import __main__

   def my_stuff():
     # do what you want with __main__.x etc.

But be careful not to use

   from __main__ import foo

at the top, because it's highly likely that foo
won't have been defined yet when the module is
imported.

--
Greg


More information about the Python-3000 mailing list