Ok, did you mean something like below?:<br><b><br>clr.AddReference(&quot;Mapack, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&quot;)<br><br>from Mapack import *</b>&nbsp;&nbsp;&nbsp;&nbsp;<b> #A library that contain classes for working with algebra etc.</b><br>
<br><b>context = {}<br><br>context[&#39;m&#39;] = Matrix(5,5)&nbsp;&nbsp;&nbsp; #creating a 5 rows, 5 columns matrix object in context<br><br><br>def inputBox_KeyDown(s, e):<br> &nbsp;key = e.Key.value__<br> &nbsp;result = root.inputBox.Text<br> &nbsp;if key == 3: #If &#39;Enter&#39; key is pressed<br>
 &nbsp; &nbsp; &nbsp; try:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root.message.Text = eval(result)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; except SyntaxError:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exec result in context<br> &nbsp; &nbsp; &nbsp; except Exception, e:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print &#39;Unhandled exception&#39;, e<br>
 &nbsp; &nbsp; &nbsp; root.inputBox.Text = &quot;&quot; #Clearing inputBox</b><br><br>But this creates a fixed size matrix and I still get an exception if I type for example <b>m=Matrix(2,2)</b> in the &#39;inputBox&#39;. I want to make this as general as possible. Can&#39;t I place everything that is imported from &#39;Mapack&#39; into the &#39;context&#39; dictionary together with whatever the user types in besides of that? There are several more classes that must be placed in &#39;context&#39;. It would be nice to have the user type <b>n=m.Transpose()</b> or whatever method he wants to get out from the &#39;Mapack&#39; library and then let the code be executed correctly.<br>
<br>Thanks very much!<br><br><br>2008/12/16 Michael Foord &lt;<a href="mailto:fuzzyman@voidspace.org.uk">fuzzyman@voidspace.org.uk</a>&gt;:<br>&gt; xkrja wrote:<br>&gt;&gt;<br>&gt;&gt; Thanks!<br>&gt;&gt;<br>&gt;&gt; I&#39;m using Ironpython with Silverlight so I can&#39;t get access to<br>
&gt;&gt; Windows.Forms<br>&gt;&gt; &nbsp;<br>&gt;<br>&gt; Ah - in which case it probably lives in System.Windows.Input<br>&gt;&gt;<br>&gt;&gt; Please bear with me :-) New stuff&#39;s showing up all the time. The solution<br>&gt;&gt; you proposed worked but there must be something I don&#39;t get with the<br>
&gt;&gt; scope.<br>&gt;&gt; Please look at my snippet below:<br>&gt;&gt;<br>&gt;&gt; &nbsp;<br>&gt;<br>&gt; The advantage of a specific context is that you control what objects the<br>&gt; code has access to. Try setting the Matrix object into the dictionary with<br>
&gt; the key &#39;m&#39; and your code should have access to it.<br>&gt;<br>&gt; Michael<br>&gt;<br>&gt;&gt; import clr, sys<br>&gt;&gt; clr.AddReference(&quot;Mapack, Version=1.0.0.0, Culture=neutral,<br>&gt;&gt; PublicKeyToken=null&quot;)<br>
&gt;&gt; from Mapack import *<br>&gt;&gt; .<br>&gt;&gt; .<br>&gt;&gt; .<br>&gt;&gt;<br>&gt;&gt; def inputBox_KeyDown(s, e):<br>&gt;&gt; &nbsp; &nbsp;key = e.Key.value__<br>&gt;&gt; &nbsp;result = root.inputBox.Text<br>&gt;&gt; &nbsp;if key == 3: #If &#39;Enter&#39; key is pressed<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; try:<br>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try:<br>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root.message.Text = eval(result)<br>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; except SyntaxError:<br>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exec result in context<br>&gt;&gt; &nbsp; &nbsp; &nbsp; except Exception, e:<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print &#39;Unhandled exception&#39;, e<br>&gt;&gt; &nbsp; &nbsp; &nbsp; root.inputBox.Text = &quot;&quot; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m = Matrix(2,2) &nbsp; &nbsp;<br>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #NOTICE: If I hard code this<br>&gt;&gt; definition in the function it works<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; print m &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#but if I try to type<br>&gt;&gt; m=Matrix(2,2) in inputBox it says:<br>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#&quot;Matrix is not defined&quot;<br>&gt;&gt;<br>
&gt;&gt;<br>&gt;&gt; I can create an object of the Matrix()-class if I code it straight into<br>&gt;&gt; the<br>&gt;&gt; function as shown in my snippet above but I can&#39;t type m=Matrix(2,2) in<br>&gt;&gt; the<br>&gt;&gt; &#39;inputBox&#39; and then execute it. Then I get an exception: &quot;Matrix is not<br>
&gt;&gt; defined&quot;.<br>&gt;&gt; How can I work around this?<br>&gt;&gt;<br>&gt;&gt; Thanks very much!<br>&gt;&gt; &nbsp;<br>&gt;&gt;<br>&gt;&gt; Michael Foord-5 wrote:<br>&gt;&gt; &nbsp;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; Oh - and Windows Forms has a Keys enumeration so that you don&#39;t have to<br>
&gt;&gt;&gt; rely on the underlying value of the event key property.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; from System.Windows.Forms import Keys<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; if e.Key == Keys.Enter:<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; (or something like that - check out the MSDN documentation for the<br>
&gt;&gt;&gt; enumeration.)<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; Michael Foord<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; &nbsp; &nbsp;<br>&gt;&gt;<br>&gt;&gt; &nbsp;<br>&gt;<br>&gt;<br>&gt; --<br>&gt; <a href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><br>
&gt; <a href="http://www.voidspace.org.uk/blog">http://www.voidspace.org.uk/blog</a><br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; Users mailing list<br>&gt; <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
&gt; <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>&gt;<br><br>