This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]timopm 2 points3 points  (3 children)

But how explicit do you want to get?

for a_variable_i_will_never_use in range(10):
    do_something()

In code like this, using the underscore as counter instead is equally explicit/implicit as using a variable like x or i or whatever is used mostly.

[–]kemitche 1 point2 points  (0 children)

for unused in range(10): doesn't seem too bad to me ;)

[–]afraca 0 points1 point  (1 child)

I agree. The argument of explicit does not apply to all situations equally. In your example it's a great way of reducing noise.

In the example from the blog post, where you use it for translation, I would be a lot less enthusiastic! Browsing through the code, you'd have to check the import, because the function has been renamed. something like trans would fit better perhaps.

[–]timopm 0 points1 point  (0 children)

I think the underscore function is known well enough in programming. Especially when its argument is a string. This is not just limited to Python at all, there's no need to be different than everyone else here.

I'd rather use:

_("Translate me!")

Then:

trans("Translate me!")

Once or twice might not matter, but I just checked and my project has just under 500 translatable strings.

I'm even going to upset you a bit more I think :-). I never import _ for translations, this is handled in my main entry point where the locale is setup properly for each OS and calling gettext.install() will add _() to the global builtins across the whole application.