报错内容 IndentationError: unindent does not match any outer indentation level

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了报错内容 IndentationError: unindent does not match any outer indentation level相关的知识,希望对你有一定的参考价值。

环境介绍

基本《Python 基础教程(第2版 修订版)》 作者:[挪] Magnus Lie Hetland 司维 曾军崴 谭颖华 译

操作系统:CentOS release 6.9 (Final)

python版本:Python 2.6.6

程序编辑器:VIM - VI IMproved 7.4


报错内容 IndentationError: unindent does not match any outer indentation level

代码:

#!/usr/bin/env python

database = [

        [‘albert‘,‘1234‘],

        [‘dilbert‘,‘4242‘],

        [‘smith‘,‘7524‘],

        [‘jones‘,‘9843‘]

]

username = raw_input(‘User name: ‘)

pin = raw_input(‘PIN code: ‘)


if [username,pin] in database:

              print ‘Access granted‘

      else:

              print ‘Hello,stranger‘

报错:

[[email protected] python]# python database1.py 

  File "database1.py", line 13

    else:

        ^

IndentationError: unindent does not match any outer indentation level

问题排查:

报错提示,没有对齐,对比分析后else 要跟if 进行左对齐

对齐后,报错问题解决。

代码:

#!/usr/bin/env python

database = [

        [‘albert‘,‘1234‘],

        [‘dilbert‘,‘4242‘],

        [‘smith‘,‘7524‘],

        [‘jones‘,‘9843‘]

]

username = raw_input(‘User name: ‘)

pin = raw_input(‘PIN code: ‘)


if [username,pin] in database:     

     print ‘Access granted‘

else:

     print ‘Hello,stranger‘


再执行成功

[[email protected] python]# python database1.py 

User name: albert

PIN code: 1234

Access granted


本文出自 “大明地盘” 博客,请务必保留此出处http://damingzone.blog.51cto.com/3892167/1953787

以上是关于报错内容 IndentationError: unindent does not match any outer indentation level的主要内容,如果未能解决你的问题,请参考以下文章

Python报错:IndentationError: expected an indented block

报错:IndentationError:unindent does not match any outer indentation level

Python自动化报错:IndentationError-unindent does not match any outer indentation level

IndentationError: expected an indented block

基本条件语句

Python错误集