转自: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

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

当前用的文本编辑器Notepad++,好像有个设置,可以显示所有的字符的。
找到了,在:
视图 -> 显示符号 -> 显示空格与制表符

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

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


而新的Python语法,是不支持的代码对齐中,混用TAB和空格的。所以出现上述错误提示了。

知道原因了,解决起来就简单了:
去把对应的TAB,都改为空格,统一一下对齐的风格,即可。
在Notepad++中,去:
设置->首选项:

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

即可实现,对于以后每次的TAB输入,都自动转换为4个空格。

【总结】

Python中遇到IndentationError,以后第一时间就要想到,是不是由于TAB键和空格混搭使用了。

估计很多人也都是此类原因导致的。记得统一一下就好。

空格和TAB键混用错误:IndentationError: unindent does not match any outer indentation level的更多相关文章

  1. [Python] 错误“IndentationError: unindent does not match any outer indentation level”是什么意思?

    文本没有对齐,建议打开文本编辑器的Tab显示(我用的Editplus是视图->空白->制表符),看缩进是否合理,调整一致就好了.

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

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

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

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

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

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

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

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

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

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

  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中出现IndentationError:unindent does not match any outer indentation level 今天在网上copy的一段代码,代码很简单,每 ...

随机推荐

  1. linux重置mysql密码

    1.使用重置脚本 wget http://soft.vpser.net/lnmp/ext/reset_mysql_root_password.sh;sh reset_mysql_root_passwo ...

  2. C# 读取app.config配置文件节点键值,提示"配置系统未能初始化" 错误的解决方案

    MSDN里写到, 如果配置文件中包含 configSections 元素,则 configSections 元素必须是 configuration 元素的第一个子元素. 将自己添加的appSettin ...

  3. Spring Boot 4 MyBatis

    SpringBoot内使用MyBatis,可以不使用xml映射配置,通过注解方式映射. pom.xml添加依赖 <dependency> <groupId>org.mybati ...

  4. 消息队列MQ

    基本版本 Queue 代码: using System.Collections.Generic; using System.Linq; using System.Web; using System.W ...

  5. 关于IOS框架的解释

  6. 从零开始攻略PHP(9)——错误和异常处理

    1.Exception类 这个类是PHP为异常处理提供的内置类.构造函数的两个参数分别是错误消息和错误代码. 除了构造函数之外,该类还提供了如下的内置方法: · getCode() 返回传递给构造函数 ...

  7. PostgreSQL Performance Monitoring Tools

    PostgreSQL Performance Monitoring Tools https://github.com/CloudServer/postgresql-perf-tools This pa ...

  8. From Disk partition to PostgreSQL installation

    From Disk partition to PostgreSQLinstallation [root@compute mnt]# fdisk /dev/sdb Welcome to fdisk (u ...

  9. csuoj 1120: 病毒

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1120 1120: 病毒 Time Limit: 3 Sec  Memory Limit: 128 ...

  10. [转]MySQL数据库引擎介绍、区别、创建和性能测试的深入分析

    本篇文章是对MySQL数据库引擎介绍.区别.创建和性能测试进行了详细的分析介绍,需要的朋友参考下   数据库引擎介绍 MySQL数据库引擎取决于MySQL在安装的时候是如何被编译的.要添加一个新的引擎 ...