[IronPython] Newbie: convert string to python expression??

xkrja kristian.jaksch at gmail.com
Tue Dec 16 10:25:39 CET 2008

I'm just starting out learning IronPython. How can I convert a string that
someone writes in a textbox to a python expression or statement?? Compare it
to the console input: If I write for example a=2 in the console it's not
just a string I assume? It becomes an expression in the python code or
something like that?

This is what I got so far:

import clr, sys
import Microsoft

clr.AddReference("Mapack, Version=, Culture=neutral,

from System.Windows import Application
from System.Windows.Controls import UserControl
from Mapack import *

class Writer(object):
    def __init__(self, element):
        self.element = element
    def write(self, text):
        self.element.Text = self.element.Text + text
def inputBox_KeyDown(s, e): #I want to check the key down events. If 'Enter'
is pressed I want the 
    root.message.Text = ''      #string that is written in the textbox to be
converted to an expression
    key = e.Key.value__         #or statement or whatever it is
    if key == 3:
        #If key '3' (Enter key) is pressed I want the text in "infoBox" to
be read and converted? How???
root = Application.Current.LoadRootVisual(UserControl(), "app.xaml")
sys.stdout = Writer(root.message)

root.inputBox.KeyDown += inputBox_KeyDown

Thanks for help!
View this message in context: http://www.nabble.com/Newbie%3A-convert-string-to-python-expression---tp21029759p21029759.html
Sent from the IronPython mailing list archive at Nabble.com.

More information about the Ironpython-users mailing list