[Python-Dev] Re: [Python-checkins] CVS: python/dist/src/Lib sre_constants.py (etc)
Tim Peters
tim_one@email.msn.com
Thu, 15 Feb 2001 19:04:32 -0500
[/F]
> 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?
I'm unclear on why __all__ was introduced, but if it's gonna be there I'd
suggest:
__all__ = [k for k in dir() if k[0] not in "_["]
del k
If anyone was exporting the name "k", they should be shot anyway <wink>.
Oh, ya, "[" has to be excluded because the listcomp itself temporarily
creates an artificial name beginning with "[".
>>> [k for k in dir()]
['[1]', '__builtins__', '__doc__', '__name__']
^^^^^
>>> dir() # but now it's gone
['__builtins__', '__doc__', '__name__', 'k']
>>>