How to clean python interpreter's environment?
Reinhold Birkenfeld
reinhold-birkenfeld-nospam at wolke7.net
Fri Aug 20 15:46:54 EDT 2004
Peter Hansen wrote:
> Reinhold Birkenfeld wrote:
>
>>>Rafal Kleger-Rudomin wrote:
>>>
>>>>I'm looking for a command to reset interpreter's environment i.e. unload
>>>>all modules, delete variables etc.
>>
>> What about something like this:
>>
>> def clear(keep=("__builtins__", "clear")):
>> keeps = {}
>> for name, value in globals().iteritems():
>> if name in keep: keeps[name] = value
>> globals().clear()
>> for name, value in keeps.iteritems():
>> globals()[name] = value
>
> Well, that only removes all the references from the
> globals of the current module. Is that all that's
> wanted?
>
> Note that threads that are already running will not be
> removed, nothing in sys.modules will be removed, and
> there are doubtless a few other things in the interpreter
> that aren't quite so easy to get at.
Right. So I agree with you on ^D.
Reinhold
--
Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows
mitbrächte, wäre das bedauerlich. Was bei Windows der Umfang eines
"kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk.
-- David Kastrup in de.comp.os.unix.linux.misc
More information about the Python-list
mailing list