3

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.

bob.sacamento
  • 6,283
  • 10
  • 56
  • 115

1 Answers1

2

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]).

Community
  • 1
  • 1
helb
  • 3,154
  • 15
  • 21
  • 1
    Well done for finding the duplicate, but after you found it, why did you answer the question rather than flag it? – Chris_Rands Feb 23 '17 at 16:02