Python编辑器设置(包括Visual Studio Code和Sublime Text3)

来源:互联网 发布:2017淘宝刷法爆款 编辑:程序博客网 时间:2024/06/16 04:30

源起

Python强制缩进,使用Tab键和空格都可以,但不能混用。混用Tab和空格会导致报错:IndentationError: unindent does not match any outer indentation level。如果你的编辑器没有可视化空格和Tab,修改起来是抓狂的。

PEP8推荐使用空格来缩进。因为不同的编辑器、IDE对Tab键的处理不一样,有的宽度为4,有的为8。


配置

下面修改一下Visual Studio Code和Sublime Text3的配置,让空格和Tab键都可视化,而且让输入Tab键时用4个空格代替1个Tab。

Visual Studio Code

File->Preferences->User Settings右侧窗口,json代码:
{
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.renderWhitespace": true,
"draw_white_space": "all"
}

Sublime Text3

Preferences->Settings User,在json配置文件中加入两项
"translate_tabs_to_spaces": true,
"draw_white_space": "all"

1 0
原创粉丝点击