my favorite line of py code so far

Peter Otten __peter__ at web.de
Sat Nov 9 14:49:39 CET 2013


Stefan Behnel wrote:

> Peter Otten, 09.11.2013 12:49:
>> There is no obvious meaning attached to _ -- so don't use it.
> 
> Not quite true. Depending on the context, the obvious meanings of "_" in
> Python are either
> 
> 1) "ignore me", e.g. in
> 
>     _, b = some_tuple
> 
> or
> 
> 2) "this is a non-public thing", as in
> 
>     class Xyz:
>         _private = 1
> 

This doesn't fit the bill provided we're discussing the name _ rather than 
any underscore.
> 
> 3) "I am the translation function", as commonly used in (HTML) templates:
> 
>     _("translation key here")
> 
> 
> None of the three meanings applies to the OP's example, AFAICT.

I can come up with one more, the last non-None result calculated in the 
interactive interpreter,

>>> 2*2
4
>>> _
4

so we're back to three. All seem to be established conventions rather than 
obvious choices.




More information about the Python-list mailing list