[转]Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level

一个python脚本,本来都运行好好的,然后写了几行代码,而且也都确保每行都对齐了,但是运行的时候,却出现语法错误:
IndentationError: unindent does not match any outer indentation level

【解决过程】
1.对于此错误,最常见的原因是,的确没有对齐。但是我根据错误提示的行数,去代码中看了下,没啥问题啊。
都是用TAB键,对齐好了的,没有不对齐的行数啊。
2.以为是前面的注释的内容影响后面的语句的语法了,所以把前面的注释也删除了。
结果还是此语法错误。
3.后来折腾了半天,突然想到了,把当前python脚本的所有字符都显示出来看看有没有啥特殊的字符。

上面这一段来源于:http://www.crifan.com/python_syntax_error_indentationerror/comment-page-1/

我使用sublime编码,最后设置空格可见:才发现tab和空格不同

编程中这种问题遇到多次,下次一定要注意

image.png

sublmie设置空格可见的教程:

Prefences -> Settings -> Default

将原来的

"draw_white_space": "selection",

修改为

"draw_white_space": "all",

用空格代替tab

// Set to true to insert spaces when tab is pressed
"translate_tabs_to_spaces": true,

你可能感兴趣的:([转]Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level)