Reputation: 346
How do I execute run Shift + Enter only the selection of highlighted lines of code in vscode?
Edit: Maybe I should be clearer.
when hitting Shift + Enter the following error :
Unable to initialize device PRN
but when I right click > run python file in terminal the code works.
Upvotes: 10
Views: 34751
Reputation: 461
To be able to run multiline selction in interactive window make sure the file is interpreted as a python file. If it is not shift+enter will work for single line, but not for multiline selection.
Upvotes: 0
Reputation: 948
Visual Studio Code supports working with Jupyter Notebooks natively, as well as through Python code files
read this article for any
https://code.visualstudio.com/docs/python/jupyter-support
Upvotes: 2
Reputation: 2663
Select one or more lines, then press Shift+Enter or right-click and select Run Selection/Line in Python Terminal. This command is convenient for testing just a part of a file.
That is what is on the VS Code documentation for Python and is what works for me. It is Shift + Enter
not Ctrl
Note that this needs the Python 3 extension to be installed.
Upvotes: 9
Reputation: 2143
You can just select the lines and then right click > Run Selection/Line in Python Terminal
.
Upvotes: 6