Question about import and namespace

Peter Otten __peter__ at web.de
Fri Sep 1 13:52:41 CEST 2006


jdemoor at gmail.com wrote:

> I'm new to Python and have the following problem :
> I have an application started by a main.py file, which does a ' from
> module_1 import * '.
> main.py is responsible from the creation of an object which is then
> used in module_1.
> What is the best way to make that object visible in the module_1
> namespace ?
> I guess that if I do an ' import module_1 ', I can make the object
> visible with ' module_1.myObject = myObject ', but that won't work with
> the from ... import * statement.

You can do both

from module import * 
import module

as these kinds of import are not mutually exclusive.
But I recommend that you restructure your modules to avoid cyclic
dependencies.

Peter



More information about the Python-list mailing list