I've been searching for the accurate answer to this question for a couple of days now but haven't got anything good. I'm not a complete beginner in programming, but not yet even on the intermediate level.
When I'm in the shell of Python, I type: dir()
and I can see all the names of all the objects in the current scope (main block), there are 6 of them:
['__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
Then, when I'm declaring a variable, for example x = 10
, it automatically adds to that lists of objects under built-in module dir()
, and when I type dir()
again, it shows now:
['__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'x']
The same goes for functions, classes and so on.
How do I delete all those new objects without erasing the standard 6 which where available at the beginning?
I've read here about "memory cleaning", "cleaning of the console", which erases all the text from the command prompt window:
>>> import sys
>>> clear = lambda: os.system('cls')
>>> clear()
But all this has nothing to do with what I'm trying to achieve, it doesn't clean out all used objects.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…