'How to kill or close a Python instance in terminal before running script

Sometimes I utilize the shift + enter Python runner (python.execSelectionInTerminal), which enters the highlighted code into a Python instance in the integrated terminal.

But when I try to run my code (arrow in top right corner), it pastes the bash script into the Python instance:

>>> print("Example")
Example
>>> /Users/freddy/.../main.py
  File "<stdin>", line 1
    /Users/freddy/.../main.py
    ^
SyntaxError: invalid syntax

Note: using the f5 debug option automatically opens and runs the debug bash script in a new terminal (which is what I want), but this doesn't happen when I click the run arrow.


How do I:

  1. Close or kill the Python instance in the integrated terminal before running the script (with the arrow in the top right corner)? Or even just type exit() before the run command if vs-code can detect Python is open.

By clicking the arrow, I am doing the same as the python.execInTerminal or Python: Run Python File in Terminal shortcut



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source