出现
IndentationError:expected an indented block
错误
一般是因为缩进问题引起的。
实例分析:
错误代码:
>>> for key in dict:
… print key,dict[key]
File “”, line 2
print key,dict[key]
^
IndentationError: expected an indented block
正确代码:
>>> for key in dict:
… print key,dict[key]
…
domain www.ouvps.com
port 80
错误代码和正确代码的区别就是print函数前多了一个空格,用肉眼是很难分辨的。
Python对缩进很敏感。
其他需要缩进的情况:
if xxxxxx:
(空格)xxxxx
或者
def xxxxxx:
(空格)xxxxx
还有
for xxxxxx:
(空格)xxxxx
一句话 有冒号的下一行往往要缩进,该缩进就缩进