python中“_”的含义是什么? [英] What's the meaning of '_' in python?

查看:370
本文介绍了python中“_”的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读Django的源代码时,我发现一些语句:

When reading source code of Django, I find some statements:

class Field(object):  
    """Base class for all field types"""  
    __metaclass__ = LegacyConnection  

    # Generic field type description, usually overriden by subclasses
    def _description(self):
        return _(u'Field of type: %(field_type)s') % {
            'field_type': self.__class__.__name__
        }    
    description = property(_description) 

class AutoField(Field):
    description = _("Integer")

我知道它将描述设置为整数,但不明白语法: description = _(Integer)

可以一些一个帮助吗?

I know it set description as 'Integer', but don't understand the syntax: description = _("Integer").
Can some one help on it?

推荐答案

请阅读国际化(i18n)

Please read up on Internationalization (i18n)

http://docs.djangoproject.com / en / dev / topics / i18n /

_ 是常用的名称将字符串转换为另一种语言的功能。

The _ is a commonly-used name for the function that translates strings to another language.

http://docs.djangoproject.com/en/dev/topics/i18n/translation/#standard-translation

另外,请阅读所有与SO相关的所有相关问题:

Also, read all of these related questions on SO:

https://stackoverflow.com/search?q=%5Bdjango%5D+i18n

这篇关于python中“_”的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆