[Python.NET] Problem in PyEval_EvalCode

MATHE MANOJ mathedotnet at gmail.com
Thu Oct 13 17:43:49 CEST 2011

Hi All

I am trying to embedded python with C#

I need to execute commands like this

*print math.sin(90)*

I am writing my code in C# using wrapper classes.

I wrote my code like this

  public void  TestCommandFileExecution(string code)


            IntPtr modulePtr = Runtime.PyImport_ImportModule("math");

            IntPtr appPtr = Runtime.PyEval_GetBuiltins();

            IntPtr srcCompilation = Runtime.Py_CompileString(code, "<stdin>",

            IntPtr execution = ExtendedRuntime.PyEval_EvalCode(srcCompilation,
appPtr, IntPtr.Zero);



And I am sending a code like this

CommandFileExecution("print 'test!'"); // Working fine

CommandFileExecution("print math.sin(90)"); // Showing a error like this.

*Traceback <most recent call last>:*

* File”<stdin>”, line 1,in <module>*

*NameError: name ‘math’ is not defined*

* *

Please help me

Thank you

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20111013/7f1578d2/attachment.html>

More information about the PythonDotNet mailing list