Michael Klier wrote:
> Dave Kuhlman wrote:
>
>> On Wed, Jul 11, 2007 at 11:03:18AM -0400, John Morris wrote:
>>
>>> I'm editing some code from Mailman and seeing:
>>>
>>> legend = _("%(hostname)s Mailing Lists")
>>>
>>>
>
> I am no python pro but I guess that funtction _() ist just a wrapper
> function around gettext.gettext from the gettext module (used for
> localization). I`ve seen that in lots of places and I think that`s
> common practise (don`t beat me if I am wrong ;-)).
>
>
>> Mailman is a great product. But that bit of code is not, I think,
>> very good code.
>>
>
> Even the python gettext docs [1] use it that way.
>
> [1] http://docs.python.org/lib/node732.html
>
>
I've seen it before, too. From the example in the manual I imagine it's
more convention than anything hard and fast, probably to make the string
stand out more than the function call since it's essentially just doing
a translation.
However, by assigning gettext.getttext to the local variable '_', you do
avoid a module lookup every time it's used. It's useful when you do
something like this (contrived example):
import math
f = math.cos
for x in range(0, 100000):
print x, f(x)
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor