python入门常见错误

1.IndentationError: unindent does not match any outer indentation level

使用的缩进方式不一致,有的是 tab 键缩进,有的是空格缩进,改为一致即可。

2.IndentationError: unexpected indent 

python编译器是在告诉你"Hi,老兄,你的文件里格式不对了,可能是tab和空格没对齐的问题",所有python对格式要求非常严格。

因此,在Python的代码块中必须使用相同数目的行首缩进空格数。

3.运行时出现NameError: name 'raw_input' is not defined

python3.x系列不再有 raw_input 函数。3.x中换成input即可。

4.fh = open("testfile.txt", "wb")运行时报错“TypeError: 'str' does not support the buffer interface”

   fh = open("testfile.txt", "w")正常运行          why?

原文地址:https://www.cnblogs.com/duoduo--up/p/5019519.html