[Tutor] Learning about callbaks

Alan Gauld alan.gauld at btinternet.com
Wed Jan 2 18:36:43 CET 2008

"Michael Bernhard Arp Sørensen" <michaelarpsorensen at stevnstrup.dk> 

> I've read what to wrote about the *parentheses*. I see why I was 
> wrong in my
> premature assumption. but I fail to understand why it did work.

I suspect that if you look closely you'll find that the "testing" 
print statement
came after the "hello world" rather than before it.

    def test_callback(self, this_callback):
        print "testing the callback"

> Anyway, I removed the parentheses from the game method and added it 
> in the
> userinput method. It still works. Do I dare say that I'm "there" 
> now? :-)

I hope so, and it should now display the "testing" message before
the "hello" message. As to whether you are "there" yet that really 
on whether you are comfortable that you understand the concept 

Can you modify the program *without modifying the classes* to use an
ordinary function as the callback? Say this goodbye function:

def goodbye():
     print "goodbye world"

This should not require more than 5 lines of new code and no changes 
to the
existing code. It could be done in 3...

If you succeed then I'll be happy that you've grasped it.

Alan G. 

More information about the Tutor mailing list