Tip: clearing up Python environment

Tim Roberts timr at probo.com
Sun Nov 19 02:26:56 CET 2000


"June Kim" <junaftnoon at nospamplzyahoo.com> wrote:

>Without terminating Python and restart it, you can do that.
>
>Put the following in a file "clear.py"
>
>#clear.py
>z=['__builtins__', '__doc__', '__name__','__1__']
>for i in [i for i in globals().keys() if i not in z]:
>    del globals()[i]
>del i

I have a question.  Is the list comprehension above really any better than
the unrolled version?

  z=['__builtins__', '__doc__', '__name__','__1__']
  for i in globals().keys():
    if i not in z:
      del globals()[i]

Seems to me we are building an extra list for nothing, and it doesn't make
the code any clearer.  Many of the list comprehension examples I've seen
seem to REDUCE comprehension.
--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list