Running Python in VSCode
This is a short guide on how to use Visual Studio Code (VSCode). Our recommendation is that you for larger projects write your functions and classes as modules in VSCode, and only use Jupyter notebooks for presenting the results. You can also run Python directly in VSCode
1. Short-cuts
Use short-cuts for changing view:
New window: Ctrl+N
Open window: Ctrl+O
Close window: Ctrl+F4
Toggle window: Ctrl+tab
Locate symbol: Ctrl+Shift+O
Go to symbol: F12 (just peak Alt+F12)
Go to line: Ctrl+G
Zoom: Ctrl++ / Ctrl+-
Zen mode: Ctrl+K,Z
Use smart short cuts for editing:
Move current line: Alt+↑ / ↓
Copy current line: Alt+Shift+↑ / ↓
Cut current line: Ctrl+X
Indent line: Tab
Deindent line: Shift+Tab
Fold/unfold:
single block: Ctrl+Shift+´ / Ctrl+Shift+å
all: Ctrl+K, Ctrl+1 / Ctrl+K, Ctrl+J
Toggle commment: Ctrl+'
Select multiple occurances: Ctrl+D (undo: Ctrl+U)
Select columns: Ctrl+Shift+Alt
Change settings Ctrl+,
Change short cuts? Ctrl+K, Ctrl+S
2. Execute Python file
The following step-by-step guide show you how to create a file, write some Python code, and execture it.
Open folder to work in: Ctrl+K, Ctrl+O
Create new file: Ctrl+N
Save new file: Ctrl+S (write e.g. test.py)
Write code: Write the following lines of code:
message = 'hello world' print(message)
Exectue file: Ctrl+Shift+P +
Python: Run Python File in Terminal
Note: The bottom-left corner should say Python 3.x 64-bit {'base': conda} when you have a .py file open. Else click on what ever else it says and choose this.
3. Interactive session
Selecet first line of code and press Shift+Enter (interactive session launched)
Select second line of code and press Shift+Enter (code is executed)
In the interactive window write
print(message)
and run with Shift+EnterNote: You can also select multiple lines to run.
4. Find errors in your code
Write the following lines of code:
message = 'hello world' print(message) print(messages)
Save file: Ctrl+S
Show all errors: Ctrl+Shift+M
Move the cursor to a line in the python file
Find next error: F8
More infromation