MS Python插件。
這是微軟官方的Python插件,已經(jīng)自帶很多功能。下面是插件功能描述,其中部分內(nèi)容我做了翻譯。
a) Linting (Prospector, Pylint, pycodestyle, Flake8, pylama, pydocstyle, mypy with config files and plugins)靜態(tài)代碼掃描(可以理解為代碼語(yǔ)法和格式錯(cuò)誤提示,支持多種linter)
b) Intellisense (autocompletion with support for PEP 484 and PEP 526)智能提示(自動(dòng)補(bǔ)全,自動(dòng)完成,包括了所在上下文的方法和變量)
c) Auto indenting自動(dòng)縮進(jìn)
d) Code formatting (autopep8, yapf, with config files)代碼自動(dòng)格式化
e) Code refactoring (Rename, Extract Variable, Extract Method, Sort Imports)代碼重構(gòu)(重命名,提取變量,提取方法,對(duì)import排序)
f) Viewing references, code navigation, view signature查看引用,代碼導(dǎo)航,查看簽名
g) Excellent debugging support (remote debugging over SSH, mutliple threads, django, flask)完美的調(diào)試支持(通過(guò)SSH遠(yuǎn)程調(diào)試,多線程,django,flask)
h) Running and debugging Unit tests (unittest, pytest, nose, with config files)運(yùn)行和調(diào)試單元測(cè)試
i) Execute file or code in a python terminal在python終端執(zhí)行文件或代碼
j) Snippets代碼片段
可見(jiàn)已經(jīng)很強(qiáng)大了,滿足了基本的需要。比如要自動(dòng)格式化代碼,只需要按下Alt+Shift+F,vscode就會(huì)調(diào)用autopep8自動(dòng)格式化代碼(題外話,VisualStudio是Ctrl+K,D)。
但是我們不滿足于此,我們要實(shí)現(xiàn)自己的style。例如Snippets,比如我們輸入for,在提示框中選擇對(duì)應(yīng)的snippet:

點(diǎn)擊回車或者tab,就變成了:
for target_list in expression_list: pass
我們?nèi)绻x自己的Snippets,比如我們想要快速輸入for xx in enumerator()方式遍歷,該如何做呢。首先打開(kāi)文件—首選項(xiàng)—用戶代碼片段。vscode會(huì)提示你選擇語(yǔ)言,我們輸入Python并回車,打開(kāi)了python.json。內(nèi)容格式為json,在根級(jí)下面新增一個(gè)自己的object,內(nèi)容如下:
"For in enumerator": { "prefix": "for/enum", "body": [ "for ${1:index}, ${2:item} in enumerate(${3:array}):", " ${4:pass}" ], "description": "For statement with enumerator" }這樣在我們輸入for/enum再按回車后,就自動(dòng)生成了:
for index, item in enumerate(array): pass
新聞熱點(diǎn)
疑難解答
圖片精選