import X between submodules in a package

Chris cwitts at gmail.com
Wed Dec 19 05:02:00 EST 2007


On Dec 19, 9:24 am, Donn Ingle <donn.in... at gmail.com> wrote:
> So, I guess I am confused about the 'scope' of what gets imported where. I
> am thinking that if one module (py file) does *import os* something and
> *then* imports another module - the second module should have access to os
> too?
>  I imagine myself "standing" inside cli.py at this point and saying "well I
> can see os, and I'm bringing config *into* this space, so they should be
> able to see os too."

Each module has its own namespace.  Why config throws an error is
because even though you imported 'os' in the cli module you are
calling an os function from a different module.  You can however put
them all together in a different manner if this helps:

#fp.py
import cli

#cli.py
import os

#config.py
import cli
print cli.os.environ['HOME']

if you wish to use the os module loaded by the cli module



More information about the Python-list mailing list