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.
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]).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With