Python-list digest, Vol 1 #10324 - 13 msgs

Bengt Richter bokr at oz.net
Sat Apr 6 16:41:43 EST 2002


On Fri, 05 Apr 2002 14:29:26 GMT, Alex Martelli <aleax at aleax.it> wrote:

>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)
                        ^-- return 
if you really want equivalent code, though maybe only side effects matter
in the the example context?

>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...
>

Regards,
Bengt Richter



More information about the Python-list mailing list