您的位置:首页 > 编程语言 > Python开发

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

2015-07-21 14:54 816 查看

源起

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"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息