当我编译下面的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
Why?
当我编译下面的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
Why?
当前回答
我正在使用Sublime Text 3与Flask项目。我修复了使用视图>缩进>选项卡宽度:4后未选择缩进使用空间的错误
其他回答
如果你使用notepad++,用扩展搜索模式做一个“替换”来找到\t并替换为四个空格。
实际上,我从一个错误的地方得到了这个。
我加上这个答案是因为我花了很多时间寻找标签。 在本例中,它与制表符或空格无关。
def some_instance_function(self):
json_response = self.some_other_function()
def compare_result(json_str, variable):
"""
Sub function for comparison
"""
json_value = self.json_response.get(json_str, f"{json_str} not found")
if str(json_value) != str(variable):
logging.error("Error message: %s, %s",
json_value,
variable) # <-- Putting the bracket here causes the error below
#) <-- Moving the bracket here fixes the issue
return False
return True
logging.debug("Response: %s", self.json_response)
# ^----The pylint error reports here
我得到这个错误,即使我没有任何制表符在我的代码,原因是有一个多余的右括号在我的代码的某处。我应该早点算出来的,因为它把等号前后的空格弄乱了……如果在IDE中运行Reformat code(或手动运行autopep8)后仍然发现任何错误,请确保所有括号都匹配,从第一个等号前后的奇怪空格开始。
如果你使用Python的IDLE编辑器,你可以按照它在类似错误消息中建议的那样做:
1)全选,如Ctrl + A
2)进入Format -> Untabify Region
3)再次检查缩进是否正确,保存并重新运行程序。
我使用的是Python 2.5.4
我正在使用Sublime Text 3与Flask项目。我修复了使用视图>缩进>选项卡宽度:4后未选择缩进使用空间的错误