[Python-Dev] Re: [Python-checkins] CVS: python/dist/src/Lib sre_constants.py (etc)

Guido van Rossum guido@digicool.com
Thu, 15 Feb 2001 18:38:04 -0500


> can anyone explain why it's a good idea to have totally
> incomprehensible stuff like
> 
>     __all__ = locals().keys()
>     for _i in range(len(__all__)-1,-1,-1):
>         if __all__[_i][0] == "_":
>             del __all__[_i]
>     del _i
> 
> in my code?

Ask Skip. :-)

This doesn't exclude anything that would be included in import* by
default, so I'm not sure I see the point either.

As for clarity, it would've been nice if there was a comment.

If it is decided that it's a good idea to have __all__ even when it
doesn't add any new information (I'm not so sure), here's a cleaner
way to spell it, which also gets the names in alphabetical order:

# Set __all__ to the list of global names not starting with underscore:
__all__ = filter(lambda s: s[0]!='_', dir())

--Guido van Rossum (home page: http://www.python.org/~guido/)