what does 'for _ in range()' mean?

Dave Benjamin ramen at lackingtalent.com
Fri Jul 30 19:00:42 EDT 2004


In article <2mvogvFr45qiU1 at uni-berlin.de>, Heike C. Zimmerer wrote:
> Dave Benjamin <ramen at lackingtalent.com> writes:
> 
>> In article <2mui6cFq81c0U1 at uni-berlin.de>, Heike C. Zimmerer wrote:
>>> Dave Benjamin <ramen at lackingtalent.com> writes:
>>> 
>>>> In Python, it's possible to use _ multiple times in the same expression,
>>> 
>>> There is, however, one objection to the use of _ as a placeholder for
>>> a dummy variable: it is used by the gettext module.  So if a program
>>> may be subject to internationalization, it is advisable to keep this
>>> name reserved, or you may run into problems.
>>
>> Speaking of which, am I the only one here that sees this _() function as a
>> total hack? Usually, having a one-character function (and a global one at
>> that!) would be considered outrageous,
> 
> I agree to some degree.  It's convention, however, and there are
> useful tools supporting it.
> 
>> and why not have global string
>> constants instead of looking up complete sentences as keys in a mapping
>> table?
> 
> This would mean introducing another level of indirection.  Having the
> entire english message inside the program text right where it is used
> saves you the need to look it up elsewhere or to guess from the name
> what it is supposed to print out.  It's easy to change the text if it
> changes its meaning.  You'd have to change both the text and its
> descriptive name otherwise.
> 
> And the additional effort of looking up the entire text shouldn't be
> much of concern; it's usually within an I/O-bound operation.
> 
>> Not that I could propose a better solution if you're trying to make
>> an already existing, large application multilingual, but still...
> 
> Yes.  Not that I couldn't think of a better solution, but for me, it
> serves its purpose and it works well.

All very good points. Thanks.

-- 
  .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:.

"When the country is confused and in chaos, information scientists appear."
Librarian's Lao Tzu: http://www.geocities.com/onelibrarian.geo/lao_tzu.html



More information about the Python-list mailing list