Question

Shane Holloway (IEEE) shane.holloway at ieee.org
Thu Aug 12 00:16:51 CEST 2004


Dag,

If you want to execute python-type statements, then you will want to use 
eval().  However, if your input is limited to smaller expressions, you 
can parse the input into pieces and then interpret them.

So, what I'm saying is that you need to provide more information.  What 
subset of eval's functionality do you need?

Regards,
-Shane Holloway

Dag Hansteen wrote:
 > I make a GUI calculator in wxPython.
 > How can I do the following without having to use eval?:
 >
 >     def OnCalc(self, event):
 >         try:
 >             regnestykke = self.formel.GetValue()
 >             svar = eval(regnestykke)
 >             svar = str(svar)
 >             self.answer.SetValue(svar)
 >         except:
 >             self.answer.SetValue("Error! Check Syntax!")
 >
 > """
 > self.formel is defined as wxTextCtrl for the input from user to be
 > calculated
 > self.answer is defined as wxTextCtrl for the answer of the users input
 > """



More information about the Python-list mailing list