"from module import *" and modifying module's top-level vars

Diez B. Roggisch deets at nospam.web.de
Sun Oct 29 21:55:06 CET 2006

lemke_juergen at yahoo.de schrieb:
> Hi everyone,
> I define some vars and functions in a "support" module which gets
> called from my
> main app module. Using Python 2.5.
> I import all symbols in the support module at the top of the main
> module through:
> from support import *
> Is there a way for me to modify a top-level ("global"?) variable
> defined in module
> support from the code in the main module and still have those changes
> visible to
> code in the support module?

No. The from foo import * will create local bindings of the 
module-globals in the importing module, and there is no implicit link to 
the module's names.

This is the main reason why the "from foo import *"-form is frowned 
upon, and you should refrain from using it.

Use e.g.

import support as s

instead, to get a shorter name for referencing the support module.


More information about the Python-list mailing list