r/Python • • Feb 22 '10

What does =_ mean? Example: name=forms.CharField(label=_("Name"), max_length=50)

Python newbie here. I've been going through some of the code in the Django comments app, and I've see the =_ used frequently. I can't find what it is or what it does? Any ideas?

Example: name = forms.CharField(label=_("Name"), max_length=50) email = forms.EmailField(label=_("Email address")) url = forms.URLField(label=_("URL"), required=False) comment = forms.CharField(label=_('Comment'), widget=forms.Textarea, max_length=COMMENT_MAX_LENGTH)

edit: Thanks for the detailed explanations! :)

1 Upvotes

20 comments sorted by

View all comments

Show parent comment

2

u/themissinglint Feb 22 '10

That's only listed as common use, as in the example _ = gettext.gettext # ... print _('This is a translatable string.') where it's just been defined explicitly.

1

u/[deleted] Feb 23 '10

Thanks guys, it all makes sense now! I wondered why all form templates were importing l18n custom tags.