【问题】 
一个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键和空格混搭使用了。

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

【Python】脚本运行报错:IndentationError: unindent does not match any outer indentation level的更多相关文章

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

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

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

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

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

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

  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

    python中出现IndentationError:unindent does not match any outer indentation level 今天在网上copy的一段代码,代码很简单,每 ...

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

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

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

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

  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. Ubuntu上查内存情况

    free -h

  2. linux memcached开机启动

    方法一: 在/etc/rc.d/rc.local 加入以下代码 /usr/local/memcached/bin/memcached -u root -d -m -l -P /tmp/memcache ...

  3. 移动端html的overflow:hidden属性失效问题

    这第一次做手机端网页,在交付测试的时候发现一个问题, 就是body的宽度,我设置了overflow:hidden,在谷歌调试的时候确实是不能滑动的,但是在手机端测试的时候发现,overflow:hid ...

  4. Java实现五子棋

    代码: package com.hotusm.datastructure.list; import com.hotusm.datastructure.Log; /** * @author luqiba ...

  5. rar压缩find查找到的文件

    find . -name 'CMakeLists.txt' | xargs /d/Program\ Files/WinRAR/rar.exe a -r ./out.rar $ ------------ ...

  6. 用开源项目ActivityOptionsICS让ActivityOptions的动画实现兼容

    我之前写过一篇文章是讲解ActivityOption的api方法的(http://www.cnblogs.com/tianzhijiexian/p/4087917.html),当时吐槽各种动画不兼容, ...

  7. 网络推送通知:及时,相关和准确 (navigator.serviceWorker.register(), window.PushManager, new Notification)

    google网络推送通知 https://developers.google.cn/web/fundamentals/push-notifications/ 服务工作线程:简介server worle ...

  8. redis(一)--认识redis

    Redis官网对redis的定义是:“Redis is an open source, BSD licensed, advanced key-value cache and store”,可以看出,R ...

  9. cobbler搭建本地的yum仓库源

    cobbler自动化安装参考文档 https://www.cnblogs.com/minseo/p/8537266.html 使用cobbler可以快速搭建一个本地的yum仓库 cobbler rep ...

  10. css学习_css写的位置

    !!!拿到一个页面后应该先写结构再写样式 结构由大到小,由外到里 样式最好按顺序加 position  .float . 颜色  背景  字体 等... 1.行内(内联)样式 2.内部样式表(按道理可 ...