What's with the underscore(_) ????
sismex01 at hebmex.com
sismex01 at hebmex.com
Thu Dec 5 09:26:30 EST 2002
> From: Alfredo P. Ricafort [mailto:alpot at mylinuxsite.com]
> Sent: Thursday, December 05, 2002 7:24 AM
>
> Hi,
>
> Look at the following codes:
>
> # file s1.py
> import gettext
> f=gettext.gettext
> _=gettext.gettext
>
>
> # file test.py
> from s1 import *
>
> print f('Hello')
> print _('Hello')
>
> Please explain to me why the 2nd print would fail with an error
> 'NameError: name '_' is not defined'.
>
> Tks.
>
>
> AL
>
Because, according to the docs, any identifier starting with "_"
in a module imported via "from <module> import *" doesn't get
imported.
This is to allow for "private" identifiers, elements which are
implementation-specific, or anything which you (as the module
creator) don't want to expose.
-gustavo
More information about the Python-list
mailing list