anonymous assignment

Mark Wooding mdw at distorted.org.uk
Tue May 13 06:20:42 EDT 2008


Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
> Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
>> You can just use a variable name than you ignore. It's traditional
>> to use _ but it's not a special keyword, it's just a another
>> variable name:
>> 
>>    y, _, d, _, _, _, _, _, _ = time.localtime()
>
> It's a terrible name for that purpose, since it doesn't indicate the
> intention explicitly,

There's a lot of tradition behind _ for this purpose, not just in
Python.  For example, pattern-matching function languages, like ML and
Haskell, have been using _ to mean `don't care' for a long time.

Just the fact that the name is repeated suggests that you don't care
about its value.  Besides, it's a good choice for other reasons:
because the symbol is short, the variables you do care about stand out
clearly.

> Far better to use the name 'unused' as suggested by Carl Banks earlier
> today.

Other traditional names are `hunoz', `hukairz' and (apparently) `huaskt.

But these have much more visual clutter than the humble _.  You actually
need to do reading to pick out the bindings which you /are/ interested
in.

-- [mdw]



More information about the Python-list mailing list