I am in the interactive mode of the python 3 interpreter.
I have created some variables of different data types. After some time I want to see a list of all variables that I have created. I tried using dir()
; but this also shows the special python builtin variables:
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
How can I print only my variables?
The easiest way to exclude them is something like this:
[val for val in dir() if val.strip('__') == val]
Just don't define any variables that start or end with __
.