Assigning to None

Michael Sparks zathras at thwackety.com
Fri Jul 1 17:29:34 EDT 2005


Mike Meyer wrote:
> Peter Hansen <peter at engcorp.com> writes:
>> Mike Meyer wrote:
>>> Yes. I once grabbed an old program that did assignments to None. But
>>> that's always been a bad idea.
>> What was the use case!?
> 
> Unpacking a tuple. Something like this:
> 
>           (foo, bar, None) = gen_tuple(stuff)

I tend to do:
   (foo, bar, _,_,_) = gen_tuple(stuff)

In cases where I decide I just want the bits I don't want. Aside from
anything else, if someone is testing things in the interactive prompt, it's
clear that the value is ephemeral, the fact it isn't name emphasises it's
unimportance and the repetition (in the above case) really makes it clear.
It also _looks_ like the value is thrown away as well.

And it doesn't clutter up your namespace...


Michael.




More information about the Python-list mailing list