On 07/05/2011 10:44 AM, David Jones wrote:
> Because I'm something of caveman, I very rarely use either form, and
> usually recommend not using ternary operator (I still have code that's
> supported on Python 2.3 and kinda supported on Python 2.2).
Yeah I think in regular code it's not that important, but I'm doing a
lot of web/UI stuff and there you often need to create short messages to
the user or embed parts of strings in other strings e.g.
# incomplete and stupid example
'Send %s a message' % (user.is_male and 'him' or 'her')
> There's also the (insanely obscure) indexing into a list trick:
>
> answer = ['no','yes'][is_it_done]
Nice pick! Actually in some situations this may be the best option for me...
> Which I have to admit a guilty fondness for when selecting array sizes:
>
> array.array('BH'[bits > 8], sometastysequence]
:)
What I like about these is that they are sufficiently pythonic to be
unambiguously readable, while the other options I mentioned tend to
interfere with my own internal Java parser and get rejected ;)
Best,
Flo
--
To post: [email protected]
To unsubscribe: [email protected]
Feeds: http://groups.google.com/group/python-north-west/feeds
More options: http://groups.google.com/group/python-north-west