I’m very new to Python, and have run into the following issue (not sure if unique to Visual Studio Code).
I tried some VERY basic code (see below). It works initially (provides correct output of “7”), but when trying to change the code (add another line), if I get a syntax error, I am unable to clear the error.
The copy of the code is below. When I open the file containing this code, it works fine. If I make some changes that happen to include an error, then I get the syntax error message (which is to be expected). However, if I then revert back to the code below (exactly as it’s shown, no changes at all), then I still get syntax errors. I have to close and reopen Visual Studio Code in order for the error to longer appear when I run the code.
Hopefully my explanation makes sense. Ultimately, my problem is the code below sometimes runs fine, other times shows syntax error. Any idea why that might happen?
There doesn’t seem to be something in this code that might be causing syntax errors. Perhaps file is not saved after reverting the changes and/or still the old version is being run? It might be helpful to include what exactly error you are getting then.
Two unrelated to the issue notes - python has build in function called sum, so calling variable like that might not be a best choice. You shouldn’t put space between print and (sum).
Thank you for the suggestion (and tips)! The save hypothesis sounded very promising, but unfortunately doesn’t seem to have solved issue.
I’ve changed the code to the following
x = 3
y = 4
taco = x + y
print(taco)
Works fine initially, but if I make changes that happen to result in a legitimate syntax error, and then revert back to the presumably error-free code above, it still keeps showing that error (even if I save again). Only solution seems to be to restart Visual Studio Code.
I believe I have some plugins (or rather modules??) that were added. I can’t recall what, to be honest.
For example, I tried following a tutorial to pull historical stock prices up using Python. I believe that required me to add a module (what exactly, I’m not sure).
And apologies, my terminology is probably all off (not sure if plug in and module are the same in this case).
“module” is most likely referring to a python library, whereas “plugin” would be a vscode extension (I forgot it calls them “extensions” and not “plugins”).
Try running code --list-extensions from a terminal and paste in the output here.