Here's the thing: My program is a GUI-based calculator written in python/GTK. In the first version I didn't used classes, so here is a piece of the old code:
def show(result):
textbox3.set_text( str(result) )
(...) # Update counters, etc.
def on_button_pressed(*args):
input_user = inputbox.get_text()
(...) # parsing of the input
show( eval( input_user ) )
For instance, if I type on inputbox "12+3" and press the button, textbox3 show the result "15".
I've modified my project to use OOP. Here's the modified code:
class App:
(...)
def show(self,result):
self.textbox3.set_text( str(result) )
(...) # Update counters, etc.
def on_button_pressed(self,*args):
input_user = self.inputbox.get_text()
(...) # parsing of the input
print input_user
self.show( eval( input_user ) )
With this code, the textbox3 show the result "<app.c12app.App instance at 0x272e128>"
. Which mistake am I making here?
P.S.:
The real code is too large, the parsing section is about 50 lines large. I added a line print input_user
to proof that the parsing don't overwrite the variable input_user
. The console prints the expression parsed (a string) correctly. But when I use the eval
function in this string it returns an object, instead the numeric value of the expression.
input_user
? Paste the rest of youron_button_pressed
method. I have a feeling you may be overwritinginput_user
somewhere. – Blender May 21 '13 at 0:17self.show()
here. You are still calling a functionshow()
; no idea what might invokeApp().show()
, but it is not in the code you show here. – Martijn Pieters May 21 '13 at 0:23self
explicitly somewhere:self.show(self)
. – Martijn Pieters May 21 '13 at 0:24self.show
(it was wrong, indeed) and added a lineprint input_user
to proof that the parsing don't overwrite the variable input_user. The console prints the expression parsed (a string) correctly. But when I use theeval
function in this string it returns an object, instead the numeric value of the expression. – David Sousa May 21 '13 at 1:00