Destroying all instances (references)
Andreas Zieringer
topdog at web.de
Mon Oct 29 09:53:27 EST 2001
>Hi,
>
>is it possible to destroy all created instances, something like an "new"
>command in basic? I
>know re-creating the interpeter would do this, but in the new interpreter I
>have to import
>all modules again and I can't do this. Is there an easy way doing this in
>pythom or with the c-api? I couldn't
>find anything in the python docu.
>
>Regards
>
>Andreas
>
>This will clear all objects in __main__ that don't start with an >underscore:
>import __builtin__
>def _init(_type='vars'):
> import sys, types
> main = sys.modules['__main__'].__dict__
> for i in main.keys():
> if not i.startswith('_'):
> if _type == 'all':
> del main[i]
> elif _type == 'vars':
> if type(main[i]) != types.ModuleType:
> del main[i]
>__builtin__.init = _init
>If you create/add this to lib/sitecustomize.py then you will be able to
>invoke init() to clear the references.
>
>HTH,
>
>Emile van Sebille
Thanks for the code, it works perfect for me. :-)
Andreas
________________________________________________________________
Lotto online tippen! Egal zu welcher Zeit, egal von welchem Ort.
Mit dem WEB.DE Lottoservice. http://tippen2.web.de/?x=13
More information about the Python-list
mailing list