Hi, Dasaratha,

As far as I can see, you will need to use a deeper layer of the API. Some of 
the Microsoft.Scripting.Hosting.ScriptEngine.CreateScriptSourceXXX() methods 
get a “path” argument which should be the one which ends up as the __file__ 
variable.

You could use CreateScriptSourceFromString() or the CreateScriptSource() 
overloads, where you pass the script contents explicitly.

To get the ScriptEngine instance, use the 
IronpPython.Hosting.Python.CreateEngine() methods.

Best regards

Markus Schaber

CODESYS® a trademark of 3S-Smart Software Solutions GmbH

Inspiring Automation Solutions
________________________________
3S-Smart Software Solutions GmbH
Dipl.-Inf. Markus Schaber | Product Development Core Technology
Memminger Str. 151 | 87439 Kempten | Germany
Tel. +49-831-54031-979 | Fax +49-831-54031-50

E-Mail: m.scha...@codesys.com<mailto:m.scha...@codesys.com> | Web: 
codesys.com<http://www.codesys.com> | CODESYS store: 
store.codesys.com<http://store.codesys.com>
CODESYS forum: forum.codesys.com<http://forum.codesys.com>

Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade 
register: Kempten HRB 6186 | Tax ID No.: DE 167014915
________________________________
This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient (or have received
this e-mail in error) please notify the sender immediately and destroy this 
e-mail. Any unauthorised copying, disclosure
or distribution of the material in this e-mail is strictly forbidden.
From: Ironpython-users 
[mailto:ironpython-users-bounces+m.schaber=codesys....@python.org] On Behalf Of 
Dasaratha Ramu Rachapudi (C)
Sent: Wednesday, April 20, 2016 10:12 PM
To: ironpython-users@python.org
Subject: [Ironpython-users] How to override the __file__ path in c#?

Hi,

How to override the python’s __file__ variables path (with a custom path rather 
than the current executing script path) in c#?
I want to do this before the python script execution through c#. I am using the 
following code snippet for overriding the __file__ variable.
Please let me know if this is the correct approach or not

ScriptScope scope2;
scope2.SetVariable("__file__", "c:/temp");


When we execute the python script this is being overwritten by python 
automatically (to current executing script path) and I am not able to get the 
c:/temp path from the __file__ variable.

Please help me resolve this issue.



Thanks & Regards,
Dasaratha R



Nothing in this message is intended to constitute an electronic signature 
unless a specific statement to the contrary is included in this message.

Confidentiality Note: This message is intended only for the person or entity to 
which it is addressed. It may contain confidential and/or privileged material. 
Any review, transmission, dissemination or other use, or taking of any action 
in reliance upon this message by persons or entities other than the intended 
recipient is prohibited and may be unlawful. If you received this message in 
error, please contact the sender and delete it from your computer.
_______________________________________________
Ironpython-users mailing list
Ironpython-users@python.org
https://mail.python.org/mailman/listinfo/ironpython-users

Reply via email to