Whats up with the _

Fredrik Lundh effbot at telia.com
Mon Feb 14 02:15:14 EST 2000


JB <jimbag at kw.igs.net> wrote:
> I have some global vars defined in a module that are prefixed with an
> underscore '_'. When I do a 'from MyModule.MyModule import *' the vars
> with the _ prefix don't get imported but when I change the names to drop
> the _ they import properly. Is this a bug or a feature? If someone could
> expalin why this is so I would appreciate it.

variables beginning with an underscore are considered
to be internal to that module.

> I missed this in the doc's.

it's sure mentioned in there:

    http://www.python.org/doc/current/ref/import.html

    If the list of identifiers is replaced by a star ("*"),
    all names defined in the module are bound, except
    those beginning with an underscore ("_").

also see:

http://www.pythonware.com/people/fredrik/fyi/fyi06.htm

which tells you to *always* use import instead of
from-import, unless You Know Exactly What You're
Doing.

</F>





More information about the Python-list mailing list