Multiple conditional expression
clp2 at rebertia.com
Fri Feb 27 00:11:28 EST 2009
On Thu, Feb 26, 2009 at 8:39 PM, Anjanesh Lekshminarayanan
<mail at anjanesh.net> wrote:
>> How do we know that from the what the OP posted?
> Its CGI alright.
> spaces = form.has_key('spaces') and form.getvalue('spaces') == '1'
> But I just dont see how
> spaces = (form.has_key('spaces') ? form.getvalue('spaces') == 1 ?
> True: False : False)
> is complicated in anyway. Its not that hard to read at all.
You have /nested/ /ternary/ expressions /without/ any disambiguating
parentheses. And you unnecessarily use boolean constants. The latter
and the stuff in italics is what makes your code hard to understand.
As I showed, you can write the *exact same thing* without using
ternary expressions at all (win!), much less nested ones, and without
any boolean constants.
And it's even 16 characters shorter.
Follow the path of the Iguana...
More information about the Python-list