A friendlier, sugarier lambda -- a proposal for Ruby-like blocks in python
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Sat Oct 14 04:25:09 EDT 2006
In <1160808124.455062.319660 at m7g2000cwm.googlegroups.com>, Kay Schluehr
wrote:
> brenocon at gmail.com wrote:
>
>> Many have complained about this crippled-ness of lambda, but it
>> actually makes some sense. Since Python uses colons and indentation to
>> define blocks of code, it would be awkward to close a multiline lambda.
>> The best I could think of would look like
>>
>> deferred.addCallback(lambda r:
>> print("fancy formatting %s" % r.text)
>> )
>>
>> ^
>> |
>>
>> That trailing paranthesis is WAY un-Pythonic.
>
> Maybe it is not common place because some users are underinformed and
> hypnotized by whitespace semantics but you can add a trailing backslash
> to achieve line coninuation within a single expression:
>
>>>> deferred.addCallback(lambda r: puts("fancy formatting %s" \
> ... ))
>
> This works syntactically.
It works just fine without the trailing backslash. A "logical line" does
not end until all opened parenthesis and brackets are matched by their
closing counterpart.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list