相关疑难解决方法(0)

IndentationError:unindent与任何外部缩进级别都不匹配

当我编译下面的Python代码时,我得到了

IndentationError:unindent与任何外部缩进级别都不匹配


import sys

def Factorial(n): # Return factorial
    result = 1
    for i in range (1,n):
        result = result * i
    print "factorial is ",result
    return result
Run Code Online (Sandbox Code Playgroud)

为什么?

python indentation

525
推荐指数
16
解决办法
136万
查看次数

如何在Python中编写一个空的缩进块?

运行时不断告诉我:

期望一个缩进的块

但是我不希望在我的except块中没有写任何内容,我只是希望它能够捕获并吞下异常.

python syntax try-catch indentation

39
推荐指数
1
解决办法
2万
查看次数

我得到一个IndentationError.我如何解决它?

我有一个Python脚本:

if True:
    if False:
        print('foo')
   print('bar')
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试运行我的脚本时,Python提出了一个IndentationError:

  File "script.py", line 4
    print('bar')
               ^
IndentationError: unindent does not match any outer indentation level
Run Code Online (Sandbox Code Playgroud)

我一直在玩我的程序,我还能够产生其他三个错误:

  • IndentationError: unexpected indent
  • IndentationError: expected an indented block
  • TabError: inconsistent use of tabs and spaces in indentation

这些错误意味着什么?我究竟做错了什么?我该如何修复我的代码?

python error-handling code-formatting exception indentation

38
推荐指数
1
解决办法
2万
查看次数

"预计缩进块"错误?

我无法理解为什么python会出现"预期的缩进块"错误?

""" This module prints all the items within a list"""
def print_lol(the_list):
""" The following for loop iterates over every item in the list and checks whether
the list item is another list or not. in case the list item is another list it recalls the function else it prints the ist item"""

    for each_item in the_list:
        if isinstance(each_item, list):
            print_lol(each_item)
        else:
            print(each_item)
Run Code Online (Sandbox Code Playgroud)

python docstring indentation

19
推荐指数
2
解决办法
22万
查看次数

IndentationError需要一个缩进块

这是代码:

def myfirst_yoursecond(p,q):

a = p.find(" ")
b = q.find(" ")
str_p = p[0:a]
str_q = p[b+1:]

if str_p == str_q:
    result = True
else:
    result = False
return result
Run Code Online (Sandbox Code Playgroud)

这是错误:

Traceback (most recent call last):
File "vm_main.py", line 26, in <module>
import main
File "/tmp/vmuser_ssgopfskde/main.py", line 22
result = False
^
IndentationError: expected an indented block
Run Code Online (Sandbox Code Playgroud)

我的代码出了什么问题?

python indentation

16
推荐指数
2
解决办法
18万
查看次数