【发布时间】:2016-07-18 06:08:54
【问题描述】:
我是python的新手。我刚刚扩展了 Hello World 程序:
import sys
def first(n):
print "Hi Man"+" Huuuuuu"
if len(sys.argv)>1: print sys.argv[1]
def second():
print "Huuuuuuuuuuu"
first(7)
if __name__=='__main__':
second()
我得到错误:
File "first.py", line 11
first(7)
^
IndentationError: unexpected indent
我阅读了What to do with "Unexpected indent" in python?,但找不到错误。
我用 python -t 命令运行:
python -t first.py
first.py: inconsistent use of tabs and spaces in indentation
File "first.py", line 12
first(7)
^
IndentationError: unexpected indent
感谢您的帮助。
【问题讨论】:
-
我复制粘贴您的代码并且没有错误。您确定您共享的代码正是您正在运行的代码吗?
-
确保不要混合使用 4 个空格和制表符。
-
在第 12 行的代码中几乎可以肯定存在缩进错误(因此是 IndentationError)。在函数中调用函数不是您的问题。修复缩进。
-
@JonSurrell 我刚刚从我的问题中复制了代码,它有效吗?它以前不起作用。
-
好像你在混合制表符和空格。
标签: python python-2.7 error-handling