lambda

Martin Franklin martin.franklin at waii.com
Wed Mar 29 09:49:10 CEST 2000


This is one of the uses I put it to......

def some_function(self, stuff):
        print stuff

def some_other_function(self):
        button - Tkinter.Button(self, command= lambda self=self, stuff='help i'm stuck': self.some_function(stuff),
                                                      text='press me').pack()


----------
If you try to pass a variable to the first function as the command from the button

eg button=Tkinter.Button(self, command=self.some_function('help me.....')

It gets executed when the button is packed (on startup) before the user presses it.....

So I guess I use it to delay a callback!?!



> > Hmm, what exactly is the use of lambda?  It just isn't clickin for some reason....  Are they just syntactical candy (such as the         > ternary operator ?: in C++ is syntactical candy..) or what. *ponders*  Anyone who could explain it, and gimme a little example > would have
> my thanx. :)







More information about the Python-list mailing list