Re:Self Hell in Python
by kevin_thibedeau on Sunday January 04, 2015 @12:54PM
(#8835165)
'_' is already idiomatic for throwaway variables. It wouldn't help matters to use it for OOP.
[ Parent
| on HN ]
In the Python world, '_' is used in three different ways:
* As a throw-away variable:
>>> a, b, _, c, d = f(t)
* As a gettext call: >>> print _('Welcome to Python')
* And at the interactive prompt as the result of the previous expression: >>> 3 + 4
7
>>> _ * 10
70As most of my Python involves localized Django, I twitch every time I see `_` used for anything other than some variation of gettext.
Re:Self Hell in Python
by lazzlazzlazz on Sunday January 04, 2015 @03:19PM
(#8835660)
Weird, since the gettext use-case is definitely the least idiomatic and least common use of `_`.
As I said, most of my Python involves localized Django. So gettext is used everywhere and (apart from the REPL) it's the other uses of `_` that are the odd ones out.
that's why you should use '__' as throw-away variable (two underscores)
Wow. How did I go years without knowing this about the repl?
Its a really crap variable name as well. I posted on Stack Overflow asking what it was doing, assuming it was some Python syntax, only to be pointed to the import at the top of the file, which was being renamed to "_". Give variables meaningful names please.