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

时间:2015-07-21 17:22:10   收藏:0   阅读:1252

源起

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"

版权声明:本文为博主原创文章,未经博主允许不得转载。

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!