There's two ways to do this: One is to expose a static (or even an instance) 
class to Python code which your C# code accesses, the other is to access the 
EngineModule and pull variables out that Python code has set.

The first can be done by:

PythonEngine pe = new PythonEngine();
EngineModule em = pe.CreateModule();

DynamicType dt = Ops.GetDynamicTypeFromType(typeof(MyType));
em.Globals["Foo"] = dt;

now Python code executed in this module can do Foo.Xyz = 3 and so on...  Or 
using an instance class:

em.Globals["Foo"] = new MyDataPasser();

The other way is to set/get from Globals directly:

em.Globals["SomeValue"] = 23;
pe.ExecuteFile("C:\\foo.py", em);
Console.WriteLine(em.Globals["SomeValue"]);



From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kaveripakam, 
Sathish
Sent: Friday, November 30, 2007 6:59 AM
To: [email protected]
Subject: [IronPython] Variable sharing between C# and iron python

Hi All,

I am using C# code and iron python V1.1 version of dll's using Visual Studio. 
In this context, I would like to read the value of the variables 
manipulated/defined in iron python files in C# and vice versa.
Any example is highly appreciated.

Regards
________________________________
Legal Notice:
The information in this electronic transmission may contain confidential or 
legally privileged information and is intended solely for the individual(s) 
named above. If you are not an intended recipient or an authorized agent, you 
are hereby notified that reading, distributing, or otherwise disseminating, 
copying or taking any action based on the contents of this transmission is 
strictly prohibited. Any unauthorized interception of this transmission is 
illegal under law. If you have received this transmission in error, please 
notify the sender by telephone [at the number indicated above/on +41 58 928 
0101] as soon as possible and then destroy all copies of this transmission.
________________________________
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to