IndentationError: expected an indented block
错误的缩进:缩进靠前,或者没有缩进。
案例一:
if crc:
fs.write(ptn + ' ' + hex(crc & (2**32-1)) + ' ' + '\n')
案例二:
if crc:
fs.write(ptn + ' ' + hex(crc & (2**32-1)) + ' ' + '\n')
IndentationError: unindent does not match any outer indentation level
错误的缩进:缩进过度,大于一个缩进长度
案例一:
except Exception, e:
print(e)
案例二:
except Exception, e:
print(e)
额外话题:
Python对缩进非常敏感,一般见“:”必定要缩进,所以同一行中缩进可以用TAB或者空格来执行,但是一定不要混合使用,缩进长度一般比上一句多一个空格或者TAB键位即可,不会控制的可以直接复制粘贴。
if xxxxxx:
(空格)xxxxx
或者
def xxxxxx:
(空格)xxxxx
还有
for xxxxxx:
(空格)xxxxx