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-boun...@lists.ironpython.com 
[mailto:users-boun...@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

-------------
sys["mySysVar"]
-------------

but they don't work.

Thanks in advance

Ernesto Cullen
_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to