__all__ as it relates to _foo, _bar, etc.

Skip Montanaro skip at pobox.com
Mon Aug 25 10:06:15 EDT 2003


    carroll>  from ModuleName import *

    carroll> if __all__ is initialized in the module, all of the names
    carroll> listed in that list are made available; if __all_ is not
    carroll> initialized, every name not beginning with an underscore is
    carroll> made available.

Correct.

    carroll> If you code:

    carroll>  import ModuleName

    carroll> Neither the __all__ or the underscore-prefixed names make any
    carroll> difference, because the names from the module are not made
    carroll> available except through an explicit reference to them (e.g.,
    carroll> ModuleName.spam)....

    carroll> Is my understanding correct?

Yes.

    carroll> If I understand this right, then, if the coder of a module
    carroll> initializes __all__, he need not worry about the _foo
    carroll> convention as far as namespaces are concerned, anyway; 

Yes, though use of a leading underscore is still a signal to people reading
your code that you don't intend _foo to be part of the exposed API.

Skip





More information about the Python-list mailing list