Make 'def' and 'class' usable within expressions

Shane Hathaway shane at zope.com
Thu Mar 25 22:11:49 CET 2004


Glenn Andreas wrote:
> Also, limiting to "one per expression" prevents you from doing something 
> like:
> 
>    myHandlers = {
>       "click" : def(x,y):
>                      print "click at x,y"
>       "enter" : def():
>                      print "mouse entered"
>       "exit"  : def():
>                      print "mouse exited"
>    }

I just thought of a better way to write this.

     myHandlers = {}
     myHandlers["click"] = def(x,y):
         print "click at x,y"
     myHandlers["enter"] = def():
         print "mouse entered"
     myHandlers["exit"] = def():
         print "mouse exited"

I think that's pretty nice.

Shane




More information about the Python-list mailing list