[IronPython] Hosting and globals

Curt Hagenlocher curt at hagenlocher.org
Tue Jan 8 17:38:47 CET 2008


On Jan 8, 2008 8:27 AM, Slide <slide.o.mix at gmail.com> wrote:
>
> So, if I have a module and inside that module I have an import
> statement. Does that imported module reside below the ScriptScope of
> the module I created?

No, each module is its own ScriptScope.  When you import one module
from another in Python, you're really doing two things:
1) Load the module if it's not already loaded
2) Create a reference to that module in the current module

There's nothing like a hierarchical relationship here.

> Adding them in the way you mention does not add them to globals.

There isn't really such a thing as a "global" global in Python in the
sense of (say) a C++ global variable.  Globals are always scoped to
the module they're in.  The closest thing there is to this in Python
is the list of loaded modules -- and even that can be manipulated,
given that it's really just a dictionary contained within the "sys"
module.

If you've done the equivalent of poking "a = 1" into module "foo", you
can access this value from __main__ by saying "from foo import a".

--
Curt Hagenlocher
curt at hagenlocher.org



More information about the Ironpython-users mailing list