[IronPython] how to access a SysModule variable from a script

Dino Viehland dinov at microsoft.com
Thu Aug 26 22:30:32 CEST 2010

Do you perhaps have 2 different script engines here?  It appears you are creating "_scriptEngine" and executing the code against that engine.  But you are getting the sys module from "scriptEngine" and setting the variable against the script engine.  If I change these to both use the same script engine it works and I can access the variable using "sys.mySysVar".

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of ecullen
Sent: Thursday, August 26, 2010 1:20 PM
To: users
Subject: [IronPython] how to access a SysModule variable from a script

hi all
    I have a program in c# which hosts IronPython scripts. I set a variable in SysModule using this:

Dictionary<String, Object> options = new Dictionary<String, Object>();
options.Add("ShowClrExceptions", true);
options.Add("ExceptionDetail", true);
options.Add("Debug", true);
ScriptEngine _scriptEngine = Python.CreateEngine(options);
ScriptScope _scriptScope = _scriptEngine.CreateScope();

ScriptScope sysScope = scriptEngine.GetSysModule();
sysScope.SetVariable("mySysVar", true);

_scriptEngine.ExecuteFile("something.py", _scriptScope);

Now, I want to read variable "mySysVar" from inside the script "something.py". How can I do that?

I tried
import sys

if sys.mySysVar:

and also


but they don't work.

Thanks in advance

Ernesto Cullen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100826/1ff28311/attachment.html>

More information about the Ironpython-users mailing list