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脚本的所有字符都显示出来看看有没有啥特殊的字符。
当前用的文本编辑器Notepad++,好像有个设置,可以显示所有的字符的。
找到了,在:
视图 -> 显示符号 -> 显示空格与制表符

然后就看出问题来了:
原来错误的行数是1580行:

但是源码的1580行的对齐用的是点点点的空格,是和前面的几行的对齐所用的箭头表示的TAB键,是不匹配的,即代码的对齐,混用了TAB键和空格:

而新的Python语法,是不支持的代码对齐中,混用TAB和空格的。所以出现上述错误提示了。
知道原因了,解决起来就简单了:
去把对应的TAB,都改为空格,统一一下对齐的风格,即可。
在Notepad++中,去:
设置->首选项:

语言->以空格取代(TAB键):

即可实现,对于以后每次的TAB输入,都自动转换为4个空格。
【总结】
Python中遇到IndentationError,以后第一时间就要想到,是不是由于TAB键和空格混搭使用了。
估计很多人也都是此类原因导致的。记得统一一下就好。
博客原文地址:http://www.crifan.com/python_syntax_error_indentationerror/comment-page-1/
Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level(转)的更多相关文章
- 【Python】脚本运行报错:IndentationError: unindent does not match any outer indentation level
[问题] 一个python脚本,本来都运行好好的,然后写了几行代码,而且也都确保每行都对齐了,但是运行的时候,却出现语法错误: IndentationError: unindent does not ...
- [Python] 错误“IndentationError: unindent does not match any outer indentation level”是什么意思?
文本没有对齐,建议打开文本编辑器的Tab显示(我用的Editplus是视图->空白->制表符),看缩进是否合理,调整一致就好了.
- IndentationError: unindent does not match any outer indentation level笔记
执行一个Python脚本的时候,报"IndentationError: unindent does not match any outer indentation level" 错 ...
- 【亲测有效】Nodepad++/Sublime Text3中Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level解决策略
我在开发游戏的时候,发现一个python脚本,本来都运行好好的,然后写了几行代码,而且也都确保每行都对齐了,但是运行的时候,却出现语法错误: IndentationError: unindent do ...
- 【已解决】Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level
转自:http://www.crifan.com/python_syntax_error_indentationerror/comment-page-1/ [问题] 一个python脚本,本来都运行好 ...
- Notepad++中Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level
使用Notepad++编辑python代码运行遇到了这个问题: IndentationError: unindent does not match any outer indentation leve ...
- 空格和TAB键混用错误:IndentationError: unindent does not match any outer indentation level
转自:http://www.crifan.com/python_syntax_error_indentationerror/comment-page-1/ [已解决]Python脚本运行出现语法错误: ...
- python中出现 IndentationError:unindent does not match any outer indentation level
python中出现IndentationError:unindent does not match any outer indentation level 今天在网上copy的一段代码,代码很简单,每 ...
- IndentationError: unindent does not match any outer indentation level解决策略
[亲测有效]Nodepad++/Sublime Text3中Python脚本运行出现语法错误:IndentationError: unindent does not match any outer i ...
随机推荐
- Node.js(window)基础(1)——用cmd命令行访问某一文件夹下的js文件
一.安装,从官网上下载安装,安装基本一直点击下一步就行.注意:node.js基于Python的,安装node.js之前电脑上要安装Python,最好是Python2.7或2.6. 二.cmd进入命令行 ...
- Git新手入门手册
1.配置email及name git config --global user.email "guxuelong@f-road.com.cn" git config --globa ...
- Make body have 100% of the browser height
Try setting the height of the html element to 100% as well. html, body { height: 100%; } Body looks ...
- Python函数式编程初级学习
函数式编程即函数可以作为参数传入函数,也可以返回函数. 1.高阶函数 函数可以作为参数传入函数. def add(x,y,f): return f(x)+f(y) ...
- python cookielib
# HttpClient.py is written by [xqin]: https://github.com/xqin/SmartQQ-for-Raspberry-Piimport cookiel ...
- hadoop namenode多次格式化后,导致datanode启动不了
jps hadoop namenode -format dfs directory : /home/hadoop/dfs --data --current/VERSION #Wed Jul :: CS ...
- Meta 的两个 相关属性
Meta标签中的apple-mobile-web-app-status-bar-style属性及含义: “apple-mobile-web-app-status-bar-style”作用是控制状态栏显 ...
- uitableview的空白处不能响应 touchesbegan 事件
现在的uitableview 的上面 响应不了 touchesbegan 事件 可能算是苹果的一个bug吧,不知道以后会不会改变 今天试了好久 都不行 最后 写了个字类 继承自 ...
- webStorm中的混乱代码格式化
Mac上 command + alt + l windows上 control + alt + l
- xfire实现webservice客户端之测试关注点
日前的工作接触到很多系统间的Webservice调用,这里想谈谈基于spring+xfire实现的webservice的客户端踩过的一些坑,需要测试关注的点. xFire的配置项 在spring中实现 ...