A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-February/012941.html below:

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

[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']
>>>




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4