torriem at gmail.com
Sat Dec 7 17:26:42 CET 2013
On 12/07/2013 09:13 AM, Rotwang wrote:
> On 07/12/2013 12:41, Jussi Piitulainen wrote:
>> if tracks is None:
>> tracks = 
> Sorry to go off on a tangent, but in my code I often have stuff like
> this at the start of functions:
> tracks = something if tracks is None else tracks
> or, in the case where I don't intend for the function to be passed
> non-default Falsey values:
> tracks = tracks or something
> Is there any reason why the two-line version that avoids the ternary
> operator should be preferred to the above?
I think for such a short operation, and for a common need like this,
what you do is fine. Personally I prefer the part you quoted from
Jussi, but your examples are just fine for correctness and readability.
I think Dan's gripes come when cleverness is taken to the extreme.
More information about the Python-list