[Python.NET] Would you share your idea how to call python command from embedded Python.Net?

Seungweon Park swpark71 at gmail.com
Mon Apr 1 20:00:02 CEST 2013


Hi,

I've been played with Python.Net for a week, but I can't find any sample to
use Python.Net in embedded way. I've searched many threads from the
previous emailing list, the result are not consistent, and looks like no
solution ??.

What I'm trying to do is that I want to get result (po) from C# code after
executing python command such as 'print 2+3' from python prompt.

When I executed it from nPython.exe, it prints out 5 as I expected.
However, when I run this code from embedded way. it returns 'null' always.
Would you give me some thoughts how I can get the execution result?

Basically, is this feature one of  Python.Net project intended for C#(.Net)
to be able to call python commands/scripts?

Thank you,
Spark.

using NUnit.Framework;
using Python.Runtime;

namespace CommonTest
{
    [TestFixture]
    public class PythonTests
    {
        public PythonTests()
        {

        }
        [Test]
        public void CommonPythonTests()
        {

            PythonEngine.Initialize();

            IntPtr gs = PythonEngine.AcquireLock();
            PyObject po = PythonEngine.RunString("print 2+3");
            PythonEngine.ReleaseLock(gs);

            PythonEngine.Shutdown();
        }
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20130401/52bd46f4/attachment.html>


More information about the PythonDotNet mailing list