[Python.NET] How to run a .py file from C#

Dylan Flaherty flatline403 at gmail.com
Tue Jun 26 20:34:42 CEST 2007


Hi,
I saw this somewhat old thread on an IronPython forum (Link:
http://mail.python.org/pipermail/pythondotnet/2006-June/000504.html, also
shown below.) and I am trying to do exactly the same thing as the person who
originally posed the question:
I would like to run .py files from within a C# program, using pythonEngine.
The .py files contain several python functions that I would like to be able
to call.

I was wondering if the newer versions of IronPython have fixed this problem
and if there is now a solution for what I'm trying to do?

Also, is there somewhere that I might find documentation as to the
functions/API for pythonEngine?

Thanks,
Dylan


-----------------------ORIGINAL
THREAD-----------------------------------------------------------------------------------------------------------

Have you tried using the PythonEngine.RunString (not
RunSimpleString) method?

Still not as convenient as having a RunFile, but that
should do what you need for now.

-Brian


>* -----Original Message-----
*>* From: pythondotnet-bounces at python.org
<http://mail.python.org/mailman/listinfo/pythondotnet>
*>* [mailto:pythondotnet-bounces at python.org
<http://mail.python.org/mailman/listinfo/pythondotnet>] On Behalf Of
LIVERNAIS Sylvie
*>* Sent: Thursday, June 01, 2006 11:08 AM
*>* To: pythondotnet at python.org
<http://mail.python.org/mailman/listinfo/pythondotnet>
*>* Subject: [Python.NET] How to run a .py file from C#
*>*
*>* Hi,
*>*
*>* I'm a newbie in C# and python and try to run a .py file from
*>* a C# program.
*>*
*>* I tried the same thing from a C++ program using
*>* PyRun_SimpleFile and in the console, I could see the python
*>* execution (the print from python).
*>*
*>* Using Python.Runtime.dll from Python.NET, I saw that such a
*>* fonction is not available, and should use
*>* PythonEngine.ImportModule and PythonEngine.RunString or
*>* PythonEngine.RunSimpleString. The thing is that it only works
*>* for a command written over one line, but if I have a "def"
*>* (which is written over several lines), the RunString doesn't
*>* work any more... So how can I run the whole file, and not
*>* only line by line ?
*>*
*>* By the way, what does exactly the ImportModule function ?
*>* Maybe the .py file is already executed but I can't see it ?
*>* Is there a way to get the output and display it in the console ?
*>*
*>* Thanks for you answer
*>*
*>* 	__ Sylvie LIVERNAIS ___________
*>* 	Applications Cartes à Puce
*>* 	EID
*>* 	* : +33 (0) 388 14 28 75 *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythondotnet/attachments/20070626/d137ec34/attachment.html 


More information about the PythonDotNet mailing list