[Pywikipedia-l] Two minor problems in replace.py (attn xqt)

Merlijn van Deen valhallasw at arctus.nl
Fri Feb 25 16:11:20 UTC 2011


On 25 February 2011 15:49, <info at gno.de> wrote:

> >>> append = True
> >>> (lambda x: x and 'a' or 'w')(append)
> 'a'
> >>> append = False
> >>> (lambda x: x and 'a' or 'w')(append)
> 'w'
>

By the way, alternative options would be:

>>> append = True
>>> append and 'a' or 'w'
'a'
>>> append = False
>>> append and 'a' or 'w'
'w'

Of course, the
>>> 'a' if append else 'w'

is nicer, but has only been supported for python 2.5+.

An alternative, third, method, would be

>>> append = True
>>> ['w', 'a'][append]
'a'
>>> append = False
>>> ['w', 'a'][append]
'w'

No reason to change the working code, of course, but just possibilies to
keep in mind.

Best regards,
Merlijn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wikimedia.org/pipermail/pywikipedia-l/attachments/20110225/cc03438a/attachment.htm 


More information about the Pywikipedia-l mailing list