Coming over from a Matlab environment to VSCode. I really miss the ability to delete variables as needed. I think this is what's happening here. I'm trying to write an equation in vscode. One of the variables was misspelled as "simga"; I inteded it to be "sigma" (NOTE THE PLACEMENT OF THE "M"). For whatever reason, it seems like vscode keeps recognizing "simga". If this were matlab, I could delete all variables and start over. Not sure how to do this in vscode. Screenshot attached for reference. Would appreciate suggestions, Thanks!
-
2have you saved the file, are you running the file you edit, add dummy print statements to see which file you run – rioV8 Feb 14 '20 at 04:12
-
@rioV8 - thanks for the response. I had saved the file. I had to reboot my PC, took care of the problem....not the best solution though. I'll try to replicate this again. – Chet Feb 14 '20 at 18:57
2 Answers
You can write your own clearvars function.
test.py
import pandas as pd
A = 123
B = 224
def clearvars():
for el in sorted(globals()):
if '__' not in el:
print(f'deleted: {el}')
del el
clearvars()
python test.py
deleted: A
deleted: B
deleted: clearvars
deleted: pd
You can delete the print statement within the function if you want.
Used sources
Edit
If you have Jupyter installed and you can use an interactive window to see which variables are in the workspace.
You can create a jupyter code cell within your .py file adding #%%
above the code you want to run. An interactive window will open with a tab variables
.

- 463
- 5
- 14
I just type del <variable>
in the interactive window and it deletes that variable. I use RSale's idea to view all of the variables, and after the DEL command the variable you want deleted should disappear from the list.
Additionally you should be able to restart your kernel and that would clear all of your variables without you having to restart the app or your computer.

- 21
- 1
- 8