2006年02月22日 星期三 15:24
我在里面经常看得到字符串外加一个_(),如_("right-click for menu")。
请问这里"_"是什么?是函数名吗?可是我没找到这个函数的声明啊。
谁知道这个函数的声明在哪里吗?
谢谢了。
--
Best Regards,
Leo Jay
2006年02月22日 星期三 15:41
yes, it is a function name
the following is copied from $PYTHONHOME/tools/i18n/pygettext.py:
import fintl
_ = fintl.gettext
----- Original Message -----
From: "Leo Jay" <python.leojay at gmail.com>
To: <python-chinese at lists.python.cn>
Sent: Wednesday, February 22, 2006 3:24 PM
Subject: [python-chinese] 有人看过Bittorrent的源代码吗?
> 我在里面经常看得到字符串外加一个_(),如_("right-click for menu")。
> 请问这里"_"是什么?是函数名吗?可是我没找到这个函数的声明啊。
> 谁知道这个函数的声明在哪里吗?
>
> 谢谢了。
>
> --
> Best Regards,
> Leo Jay
>
--------------------------------------------------------------------------------
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
2006年02月22日 星期三 16:03
这是gettext使用的,不是python的函数, 在使用gettext进行国际化的PHP程序中,也可看到_('xxx')等内容
更详细信息可在google查询
2006年02月22日 星期三 16:19
On 2/22/06, Slowness Chen <chenzh at bhh.com.cn> wrote: > yes, it is a function name > the following is copied from $PYTHONHOME/tools/i18n/pygettext.py: > > import fintl > _ = fintl.gettext > thanks for your reply. but i still wonder where is the definition of the "_" function. following your desc, i tried the code as follows: >>> import gettext >>> _("test") Traceback (most recent call last): File "", line 1, in ? NameError: name '_' is not defined >>> gettext._("test") Traceback (most recent call last): File " ", line 1, in ? AttributeError: 'module' object has no attribute '_' as can be seen from the result, i don't think the "_" function is declared in the gettext module. so, where is it? Thanks -- Best Regards, Leo Jay
2006年02月22日 星期三 17:06
do this:
from gettext import gettext as _
_ is just a shortcut alias for gettext (or *gettext)
which can be from standard library or fintl.py
----- Original Message -----
From: "Leo Jay" <python.leojay at gmail.com>
To: <python-chinese at lists.python.cn>
Sent: Wednesday, February 22, 2006 4:19 PM
Subject: Re: [python-chinese] 有人看过Bittorrent的源代码吗?
On 2/22/06, Slowness Chen <chenzh at bhh.com.cn> wrote:
> yes, it is a function name
> the following is copied from $PYTHONHOME/tools/i18n/pygettext.py:
>
> import fintl
> _ = fintl.gettext
>
thanks for your reply.
but i still wonder where is the definition of the "_" function.
following your desc, i tried the code as follows:
>>> import gettext
>>> _("test")
Traceback (most recent call last):
File "", line 1, in ?
NameError: name '_' is not defined
>>> gettext._("test")
Traceback (most recent call last):
File " ", line 1, in ?
AttributeError: 'module' object has no attribute '_'
as can be seen from the result, i don't think the "_" function is
declared in the gettext module.
so, where is it?
Thanks
--
Best Regards,
Leo Jay
_______________________________________________
python-chinese
Post: send python-chinese at lists.python.cn
Subscribe: send subscribe to python-chinese-request at lists.python.cn
Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Zeuux © 2025
京ICP备05028076号