Python-list digest, Vol 1 #10324 - 13 msgs
Alex Martelli
aleax at aleax.it
Fri Apr 5 09:29:26 EST 2002
Jonathan Claggett wrote:
...
> Actually, I really wasn't thinking in terms of functional programming (I
> can't Lisp my way out of a paper bag :-). My immediate motive was only
> skin deep in that I'd like to replace the (unique) lambda syntax in my
> code with the (standard) def syntax.
You can do that now! def is a statement and you can put it wherever you
need. Just choose a good name, as you would for some complicated
sub-expression in order to clarify things. For example, instead of
Button(buttonsFrame, text='Squirk', command=lambda: self.squirkIt(23, 45))
you can code:
def specificSquirker(): self.squirkIt(23, 45)
Button(buttonsFrame, text='Squirk', command=specificSquirker)
It's generally not hard to come up with a name which helps readability.
I think un-lambdaing your code in this way is a good thing...
Alex
More information about the Python-list
mailing list