Re: [IronPython] Hosting and globals
On Jan 8, 2008 8:27 AM, Slide <[EMAIL PROTECTED]> 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 [EMAIL PROTECTED] ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Hosting and globals
On Jan 8, 2008 9:17 AM, Curt Hagenlocher <[EMAIL PROTECTED]> wrote: > On Jan 8, 2008 6:58 AM, Slide <[EMAIL PROTECTED]> wrote: > > I am trying to update my application to use the Hosting APIs from > > alpha 7, one thing that I can't seem to figure out is how to access > > "globals" to add stuff from my application to be used by the script. > > What kind of reference do you have to the script from the hosting > code? If you've got a ScriptScope for the module, you can just say > > PythonEngine.CurrentEngine.SetVariable(module, "varName", varValue) > > where module is the ScriptScope. > > -- 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? The reason I ask is that I have a file that I create a module from called __main__. I then add some variables to that module __main__.SetVariable("name", value). I would think that I need to access them by importing my original script and referencing them that way; what I want to do is access them via the globals(). Adding them in the way you mention does not add them to globals. Thanks, slide ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Hosting and globals
On Jan 8, 2008 6:58 AM, Slide <[EMAIL PROTECTED]> wrote: > I am trying to update my application to use the Hosting APIs from > alpha 7, one thing that I can't seem to figure out is how to access > "globals" to add stuff from my application to be used by the script. What kind of reference do you have to the script from the hosting code? If you've got a ScriptScope for the module, you can just say PythonEngine.CurrentEngine.SetVariable(module, "varName", varValue) where module is the ScriptScope. -- Curt Hagenlocher [EMAIL PROTECTED] ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
[IronPython] Hosting and globals
I am trying to update my application to use the Hosting APIs from alpha 7, one thing that I can't seem to figure out is how to access "globals" to add stuff from my application to be used by the script. Any help would be appreciated. Thanks, slide ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com