What does __ALL__ mean?

John Roth johnroth at ameritech.net
Fri Feb 28 07:25:20 EST 2003


"Erik Max Francis" <max at alcyone.com> wrote in message
news:3E5EABA1.B3F3F1E7 at alcyone.com...
> John Roth wrote:
>
> > If you want to maintain absolute control over the API, yes.
>
> Note that it doesn't prevent people from manipulating the "non-public"
> contents if they know their names, nor does it prevent them from
> appearing as module attributes with dir, etc.  __all__ simply affects
> what is important with from module import *, and that is all:
>
> max at oxygen:~/tmp% cat > sample.py
> __all__ = ['x', 'y', 'z']
> x, y, z = range(3)
> a, b = range(2)
> _p, _q, _r = range(3)
> ^D
> max at oxygen:~/tmp% python
> Python 2.2.2 (#2, Oct 14 2002, 17:32:20)
> [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import sample
> >>> from sample import *
> >>> dir()
> ['__builtins__', '__doc__', '__name__', 'sample', 'x', 'y', 'z']
> >>> dir(sample)
> ['__all__', '__builtins__', '__doc__', '__file__', '__name__', '_p',
> '_q', '_r', 'a', 'b', 'x', 'y', 'z']
> >>> sample.a
> 0
> >>> sample._r
> 2
>
> I'm sure you know this, I'm just clarifying for the original poster.

As I said two lines above the one you quoted.

John Roth

>
> --
>  Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
>  __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
> /  \ It's soulful music.  It doesn't necessarily sound like ... soul
...
> \__/ Sade Adu
>     Official Omega page / http://www.alcyone.com/max/projects/omega/
>  The official distribution page for the popular Roguelike, Omega.






More information about the Python-list mailing list