Python-list digest, Vol 1 #10572 - 14 msgs
Robert Amesz
sheershion at mailexpire.com
Wed Apr 24 08:30:15 EDT 2002
Delaney, Timothy wrote:
> I would rewrite this as:
>
> def both_ways (val, direction):
>
> if dir:
> arg1, arg2 = None, val
> else:
> arg1, arg2 = val, None
>
> another_func(arg1, arg2, ...)
>
> The thing is, the ternary operator is only more readable when
> dealing with a single condition and single results. Adding even a
> single expression in there starts making it unreadable. Any time
> things get more complicated, you need to move to the if () {} else
> {} format anyway.
I'd still say this is more explicit and readable:
def both_ways (val, direction):
if dir:
another_func(None, val, ...)
else:
another_func(val, None, ...)
Of course, if the argument list for 'another_func' is very long the
readability argument might swing the other way.
Robert Amesz
More information about the Python-list
mailing list