In VSCode, I can run Python code from a .py file by selecting the code in the editor then typing shift+enter. It runs without error and opens a Python terminal (prompt turns to >>>). However, when my prompt turns to >>>, the below approaches to running code produce both SyntaxError: invalid syntax and KeyboardInterrupt errors:
- Left-clicking the arrow button near the top right of the screen and selecting "Run Python File"
- Right-clicking the editor and selecting "Run Python File in Terminal"
Other approaches involving the arrow button, right-clicking the editor, or use of shift+enter do not produce these errors. Additionally, if I use any approach that doesn't produce the >>> prompt, none of these produce an error.
Can anyone explain what is going on? I can't find any documentation explaining what is happening with the terminal and how it relates to these errors. FWIW, I'm working with a virtual environment containing only numpy.
Here's an example .py file:
import numpy as np
msg = "Roll a dice!" # in-line comment
print(msg)
print(np.random.randint(1,9))
print(5+5) # in-line comment