python中出现IndentationError:unindent does not match any outer indentation level

今天在网上copy的一段代码,代码很简单,每行看起来该缩进的都缩进了,运行的时候出现了如下错误: 

【解决过程】 
1.对于此错误,最常见的原因是,的确没有缩进。根据错误提示的行数,去代码中看了下,看起来没有什么问题呀,都有缩进,而且语法也没有错误呀。

2.仔细研究了下代码,发现真的看不出什么问题,突然想到了,把当前python脚本的所有字符(包括空格和tab字符)都显示出来看看到底有没有缩进或者是其他特殊的字符。

当前用的文本编辑器Notepad++,有个设置,可以显示所有的字符的。 
在: 
视图 –> 显示符号 –> 显示空格与制表符 
这样就可以看到我们Python代码的到底有没有该缩进的都缩进了。

最终发现代码报错原因还真是出在这里,错误提示的这行看起来是缩进了,实际上确没有缩进,这就是问题的根源所在。

发现了个问题,发现copy过来的Python代码都没有进行缩进,当我们copy别人的代码时,缩进这点需要额外注意。不要看起来代码缩进了就感觉ok了,实际上是没有缩进的。

python中出现 IndentationError:unindent does not match any outer indentation level的更多相关文章

  1. 【亲测有效】Nodepad++/Sublime Text3中Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level解决策略

    我在开发游戏的时候,发现一个python脚本,本来都运行好好的,然后写了几行代码,而且也都确保每行都对齐了,但是运行的时候,却出现语法错误: IndentationError: unindent do ...

  2. Notepad++中Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level

    使用Notepad++编辑python代码运行遇到了这个问题: IndentationError: unindent does not match any outer indentation leve ...

  3. Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level(转)

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

  4. 【Python】脚本运行报错:IndentationError: unindent does not match any outer indentation level

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

  5. 【已解决】Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level

    转自:http://www.crifan.com/python_syntax_error_indentationerror/comment-page-1/ [问题] 一个python脚本,本来都运行好 ...

  6. 空格和TAB键混用错误:IndentationError: unindent does not match any outer indentation level

    转自:http://www.crifan.com/python_syntax_error_indentationerror/comment-page-1/ [已解决]Python脚本运行出现语法错误: ...

  7. IndentationError: unindent does not match any outer indentation level笔记

    执行一个Python脚本的时候,报"IndentationError: unindent does not match any outer indentation level" 错 ...

  8. IndentationError: unindent does not match any outer indentation level解决策略

    [亲测有效]Nodepad++/Sublime Text3中Python脚本运行出现语法错误:IndentationError: unindent does not match any outer i ...

  9. Python运行语法错误:IndentationError: unindent does not match any outer indentation level

    python脚本没有对齐.新的Python语法,是不支持的代码对齐中,混用TAB和空格的.

随机推荐

  1. 动态库对外暴露api的方法

    1 windows的动态库 在要export的函数声明的前面加上__declspec(dllexport)标识这个函数是从该dll中export出来给其它模块使用的. declspec是declare ...

  2. cocos2d-js v3.1的坑

    前几天因为要用到cc.pool,所以就换了v3.1版本,结果连生成apk的出错(cocos code ide), log显示为:error: relocation overflow in R_ARM_ ...

  3. POJ 2348 Euclid Game (模拟题)

    Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7942   Accepted: 3227 Des ...

  4. LINQ to Entities 不识别方法"System.String ToString()",因此该方法无法转换为存储表达式 的解决方法

    一.案例1,及解决方案: "LINQ to Entities 不识别方法"System.String ToString()",因此该方法无法转换为存储表达式." ...

  5. smokeping高级配置

    摘自: http://mayulin.blog.51cto.com/1628315/514367 自定义报警 http://www.cnblogs.com/thatsit/p/6395506.html

  6. CentOS7 网络管理工具nmcli

    今天帮别人调试虚拟机的网络问题(CentOS 7系统),习惯性直接改/etc/sysconfig/network-scripts/ifcfg-xxx配置文件,但是不知道为什么重启network后静态i ...

  7. insert …select …带来的死锁问题

    mysql中 insert …select …带来的问题 当使用insert...select...进行记录的插入时,如果select的表是innodb类型的,不论insert的表是什么类型的表,都会 ...

  8. Go丨语言学习笔记--func

    Java语言跟Go语言的函数比较 Go语言 func funcName(input type1,input type2,......)(output type1,output type2,...... ...

  9. linux网络编程 inet_aton(); inet_aton; inet_addr;

    . inet_aton()是一个改进的方法来将一个字符串IP地址转换为一个32位的网络序列IP地址. . inet_ntoa() 本函数将一个用in参数所表示的Internet地址结构转换成以“.” ...

  10. android自定义控件(三) 增加内容 自定义属性 format详解

    转自 http://www.gisall.com/html/35/160435-5369.html 1. reference:参考某一资源ID. (1)属性定义: <declare-stylea ...