Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Wiping the slate clean" in python [duplicate]

Tags:

python

del

This should be pretty basic, but I can't find anything on it, so ... In python, if I want to just clear out my whole session and start all over without shutting down and starting over, how do I do it? I want to delete all objects, class defs, function defs, etc. A couple of things I have tried that don't work are

>>> del(dir())

and

>>> del(dir()[:])

I used to know this, and it's something like this, but I can't remember the command. I am sure this is dangerous. I promise I will use it only for good.

like image 526
bob.sacamento Avatar asked Sep 12 '26 06:09

bob.sacamento


1 Answers

It's possible, but probably not a good idea. See this: How do I clear all variables in the middle of a Python script?

It destroys even builtins, so the shell remains kinda broken after that. You can loop over the dir and omit builtins as mentioned, but I don't see why on Earth would i want to do that rather that simply exiting and running python again ([ctrl]-[d] [up arrow] [enter]).

like image 109
helb Avatar answered Sep 14 '26 19:09

helb