[IronPython] Newbie: convert string to python expression??
kristian.jaksch at gmail.com
Tue Dec 16 17:13:03 CET 2008
I'm using Ironpython with Silverlight so I can't get access to Windows.Forms
Please bear with me :-) New stuff's showing up all the time. The solution
you proposed worked but there must be something I don't get with the scope.
Please look at my snippet below:
import clr, sys
clr.AddReference("Mapack, Version=18.104.22.168, Culture=neutral,
from Mapack import *
def inputBox_KeyDown(s, e):
key = e.Key.value__
result = root.inputBox.Text
if key == 3: #If 'Enter' key is pressed
root.message.Text = eval(result)
exec result in context
except Exception, e:
print 'Unhandled exception', e
root.inputBox.Text = ""
m = Matrix(2,2) #NOTICE: If I hard code this
definition in the function it works
print m #but if I try to type
m=Matrix(2,2) in inputBox it says:
#"Matrix is not defined"
I can create an object of the Matrix()-class if I code it straight into the
function as shown in my snippet above but I can't type m=Matrix(2,2) in the
'inputBox' and then execute it. Then I get an exception: "Matrix is not
How can I work around this?
Thanks very much!
Michael Foord-5 wrote:
> Oh - and Windows Forms has a Keys enumeration so that you don't have to
> rely on the underlying value of the event key property.
> from System.Windows.Forms import Keys
> if e.Key == Keys.Enter:
> (or something like that - check out the MSDN documentation for the
> Michael Foord
View this message in context: http://www.nabble.com/Newbie%3A-convert-string-to-python-expression---tp21029759p21036162.html
Sent from the IronPython mailing list archive at Nabble.com.
More information about the Ironpython-users