<div dir="ltr">A hosting API global is not the same as a Python global. After all, Python globals aren't really global; they're scoped to the module you're in. I can't provide sample code offhand, but to do what you want, you'll need to do something like the following steps:<br>
<br>1) Create an empty script scope<br>2) Set the "name" variable in that scope<br>3) Load your source into that already-created scope instead of creating a new one.<br><br>There are probably better ways to structure this code, but it looks like you're just working out a test program so I won't be pedantic about it.<br>
<br>In this sample code, you also haven't loaded System.Windows.Forms.dll; you can do that either through Python with clr.AddReference or from the hosting code with env.LoadAssembly.<br><br><div class="gmail_quote">On Sun, Aug 10, 2008 at 1:22 AM, Huzaifa <span dir="ltr"><<a href="mailto:huzi_1982@hotmail.com">huzi_1982@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
i am trying this code and it is giving me exception<br>
"$exception {"name 'name' is not defined"} System.Exception<br>
{System.Scripting.Runtime.UnboundNameException}<br>
"<br>
CODE:<br>
<br>
ScriptRuntime env = ScriptRuntime.Create ( );<br>
ScriptScope defaultScope = env.CreateScope ( );<br>
ScriptEngine curEngine = env.GetEngine ("py");<br>
ScriptSource input;<br>
<br>
env.LoadAssembly (typeof (System.Diagnostics.Debug).Assembly);<br>
env.Globals.SetVariable("name","Huzaifa");<br>
<br>
input = curEngine.CreateScriptSourceFromString (<br>
@"import clr<br>
from System import *<br>
from System.Windows.Forms import *<br>
<br>
MessageBox.Show(name)<br>
", SourceCodeKind.Statements);<br>
<br>
input.Execute (defaultScope);<br>
<font color="#888888"><br>
<br>
--<br>
View this message in context: <a href="http://www.nabble.com/System.Scripting.Runtime.UnboundNameException-tp18911599p18911599.html" target="_blank">http://www.nabble.com/System.Scripting.Runtime.UnboundNameException-tp18911599p18911599.html</a><br>
Sent from the IronPython mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
</font></blockquote></div><br></div>