8法VSCODE運行python代碼(親測可用)

介紹

這裏小虎介紹8種方法利用vscode運行python的代碼,親測有效,可以參考使用。請在配置好環境後展開。

小技巧

在當前文件夾下,下面可以用vscode打開當前文件夾編程。

code.

Run

method 1

在這裏插入圖片描述
記得選右下角編譯器。
在這裏插入圖片描述

method 2

在編輯窗口按鼠標右鍵。
在這裏插入圖片描述

method 3

框選代碼,然後鍵盤輸入下面幾句。此法用於測試少數幾行代碼,跟斷點測試不同,斷點是從前往後,此法可運行只運行中間幾行。

shift + enter

在這裏插入圖片描述

method 4

打開command palette,然後輸入選擇Python: start REPL。這跟直接在terminal裏面輸入python是一樣的。

shift + Ctrl + P
Python: start REPL

在這裏插入圖片描述

然後在terminal輸入你想運行的代碼。這個也是僅運行幾行的。
在這裏插入圖片描述
退出的話,輸入

^Z

或者鍵盤:

Ctrl + z

之後回車

method 5

F5,選擇python file即可。
在這裏插入圖片描述
斷點運行。打斷點後,同上。
在這裏插入圖片描述
在這裏插入圖片描述
去除斷點的話就可以直接運行全部了。

method 6

在上一方法中,在debug console裏面run。
在這裏插入圖片描述
斷點測試快捷鍵
A debug toolbar appears along the top with the following commands from left to right: continue (F5), step over (F10), step into (F11), step out (Shift+F11), restart (Ctrl+Shift+F5), and stop (Shift+F5).

method 7

用Django。如果沒有設置過launch.json的話,F5,然後選擇Django。輸入文件名字,即可運行。
在這裏插入圖片描述
在這裏插入圖片描述

method 8

在這裏插入圖片描述
launch配置1:
在這裏插入圖片描述

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

launch配置2:
在這裏插入圖片描述

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}\\hello.py",
            "args": [
                "runserver",
                "--noreload"
            ],
            "django": true
        }
    ]
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章