<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.3103.1000" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>
<DIV>I make a GUI calculator in wxPython.</DIV>
<DIV>How can I do the following without having to use eval?:</DIV>
<DIV> </DIV>
<DIV> def OnCalc(self,
event):<BR>
try:<BR>
regnestykke =
self.formel.GetValue()<BR>
svar =
eval(regnestykke)<BR>
svar =
str(svar)<BR>
self.answer.SetValue(svar)<BR>
except:<BR>
self.answer.SetValue("Error! Check Syntax!")</DIV>
<DIV> </DIV>
<DIV>"""<BR>self.formel is defined as wxTextCtrl for the input from user to be
calculated <BR>self.answer is defined as wxTextCtrl for the answer of the users
input</DIV>
<DIV>"""</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>"Thomas Krüger" <<A
href="mailto:thomas.krueger@gmx.net">thomas.krueger@gmx.net</A>> skrev i
melding <A
href="news:cf8ehd$kuk$03$1@news.t-online.com">news:cf8ehd$kuk$03$1@news.t-online.com</A>...</DIV>>
Dag Hansteen wrote:<BR>> <BR>> >>>> s = "2+2"<BR>>
>>>> answer = int(str(s))<BR>> > Traceback (most recent call
last):<BR>> > File "<pyshell#64>", line 1, in ?<BR>>
> answer = int(str(s))<BR>> > ValueError:
invalid literal for int(): 2+2<BR>> > <BR>> > How do I this ? I have
a string with a such expression and I want to<BR>> > return the answer in
a variable.<BR>> <BR>> eval('2+2')<BR>> -> 4<BR>> <BR>>
Thomas<BR>> <BR>> -- <BR>> <A
href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</A><BR>>
<BR>> <BR>> </FONT></DIV></BODY></HTML>