<HTML>
<HEAD>
<TITLE>Re: [Python.NET] RunString does not work</TITLE>
</HEAD>
<BODY>
<FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>FYI, if you are getting a NameError using RunString that usually means that the string <BR>
you run needs to do some imports &#8212; remember that RunString creates (essentially) a <BR>
totally new global local namespace, so you&#8217;ll need to import any names you need in <BR>
your code snippet.<BR>
<BR>
e.g.<BR>
<BR>
&nbsp;&nbsp;CLR.Food.SpamAndEggs.cook()<BR>
<BR>
&nbsp;&nbsp;...will fail<BR>
<BR>
but<BR>
<BR>
&nbsp;&nbsp;import CLR<BR>
&nbsp;&nbsp;import CLR.Food<BR>
&nbsp;&nbsp;CLR.Food.SpamAndEggs.cook()<BR>
<BR>
&nbsp;&nbsp;...should work<BR>
<BR>
<BR>
hope this helps,<BR>
<BR>
-Brian<BR>
<BR>
<BR>
On 3/4/07 4:37 AM, &quot;Seshagiri Cherukuri&quot; &lt;seshagiri.cherukuri@gmail.com&gt; wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>hi All, <BR>
&nbsp;<BR>
I have embedded pythonnet into my C# application and this works great as far as creating .net objects from python, executing methods etc. <BR>
Here I am using the RunSimpleString (the PyRun_SimpleString) wrapper to send commands from the C# application to the pythonnet. <BR>
&nbsp;<BR>
However I am facing the following problems: <BR>
&nbsp;<BR>
1. After RunSimpleString, PyErr_Occurred or PyErr_Fetch are not able to detect any exceptions even if they did occur<BR>
- for example, consider the code - curErr = <FONT COLOR="#008080">PythonEngine</FONT>.RunSimpleString(<FONT COLOR="#800000">&quot;10/0\n&quot;</FONT> ); <BR>
- this code does return a -1 value indicating error.<BR>
- however after this none of PyErr_Occurred or PyErr_Fetch do not detect this error<BR>
- from python documentation it looks like there is no way to obtain the exception information<BR>
&nbsp;<BR>
2. using RunString<BR>
- because of above problem I want to send a multi-line code including a try-except: block<BR>
- I have tried using RunString with all the three modes - <FONT COLOR="#008000">Py_eval_input, Py_single_input and Py_file_input<BR>
- The RunString works only if the code does not have any .net objects or does not include any .net exceptions<BR>
- If the code sent to RunString includes a .net object e.g. obj, then RunString always returns in NameError, obj is not defined<BR>
</FONT> <BR>
<FONT COLOR="#008000">3. Strangely, if I run the console application, it is able to work with .net exceptions - both .net and user defined exceptions<BR>
</FONT> <BR>
<FONT COLOR="#008000">4. Is this because of the new dictionary created while in RunString? <BR>
</FONT> <BR>
<FONT COLOR="#008000">thanks<BR>
</FONT> <BR>
Sesh Cherukuri<BR>
<BR>
<HR ALIGN=CENTER SIZE="3" WIDTH="95%"></SPAN></FONT><FONT SIZE="2"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:10.0px'>_________________________________________________<BR>
Python.NET mailing list - PythonDotNet@python.org<BR>
<a href="http://mail.python.org/mailman/listinfo/pythondotnet">http://mail.python.org/mailman/listinfo/pythondotnet</a><BR>
</SPAN></FONT></FONT></BLOCKQUOTE><FONT SIZE="2"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:10.0px'><BR>
</SPAN></FONT></FONT>
</BODY>
</HTML>