简体   繁体   中英

How do I find/excute Python Interactive Mode in Visual Studio Code?

I'm unable to find/execute the interactive mode in visual studio code - could you guys step-by-step me? Seems like a ridiculous question, I guess, but none of the waypoints I Googled seem to work;

I don't have "other windows"

If there's something I need to install, please let me know.

(Yes, I'm a beginner).

In VSCode, you can enter the Python interactive window in the following places:

Option 1

F1 -> Python: Create Python Interactive Window

This is the Python interactive window that comes with VSCode. You can enter the interactive window without inputting instructions. Please use " Ctrl + Enter " to execute the code:

option1_screenshot

Option 2

Ctrl + Shift + `

This is the cmd window that comes with the VSCode integration computer. We need to enter the command " python " to enter the Python interactive window:

option2_screenshot

PS

For more information about using Python in Visual Studio Code , you can refer to the official VSCode documentation: Python in VSCode .

If you have the Python extension, you can use the Python Interactive feature (this is a IPython/Jupyter console, which can run parts of your code as 'cells', ie snippets of code executed in one go).

This article writes about the interactive window and many more possibilities of using Jupyter in VS Code: https://code.visualstudio.com/docs/python/jupyter-support-py

Best option

When editing Python code, select something and press Shift + Enter . This will open the interactive window and run your selection as a single cell.

I have personally been annoyed many times by accidentally pressing Shift + Enter instead of Enter on a line of code which (alone) would be a syntax error. Then, one day I decided to start using this feature consciously.

Terminal fallback

Press:

Ctrl+`

This opens a system shell (bash, or on Windows: Powershell or cmd). Run python , or ipython if you have it ( pip install ipython ), and use the interactive window. In the terminal, you can also execute your script, by typing python myscript.py arguments .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM