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

Konrad Delong konryd at gmail.com
Tue Dec 16 11:21:56 CET 2008

2008/12/16 xkrja <kristian.jaksch at gmail.com>:
> Hi,
> 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

If I understood well, you're looking for eval() function. You use it this way:
eval("1 + 4") # => 5

In your case:
root.message.Text = eval(root.message.Text)

eval() is one of the built-in python functions. You can read about
rest of them on

hope that answers your question.

More information about the Ironpython-users mailing list