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

brad at fie.us brad at fie.us
Mon Apr 1 20:08:24 CEST 2013


Yes it is supposed to work.

But I'd point out that there is a big difference between the statements:

print 2+3

and

2+3

What exactly would you expect to get back as a return from the print statement?

On Apr 1, 2013, at 2:00 PM, Seungweon Park <swpark71 at gmail.com> wrote:

> 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();
>         }
>     }
> }
> 
> _________________________________________________
> Python.NET mailing list - PythonDotNet at python.org
> http://mail.python.org/mailman/listinfo/pythondotnet



More information about the PythonDotNet mailing list