indentationError:unexpected indent
原因:缩进错误
纠正缩进方式
SyntaxError:invalid character in identifier
原因:输入了中文标点符号
TypeError:‘xxx’ object does not support item assignment
原因:python不允许对“不可变量”进行修改/赋值操作(例如元组)
TypeError:unsupported operand type(s) for xxx
不支持自动类型转换
index Error:list index out of range
原因:序列的下标超出了边界
TypeError:type() takes xxx arguments
原因:函数调用时给出的“实参”与“形参”不一致
SyntaxError:unexpected EOF while parsing
原因:语句未结束或者表达式不完整
ModulNotFoundError:No module named xxx
原因:未安装模块
TypeError:‘list’ object is not callable
原因:对应无法调用
通常,将“属性”错误用为“方法”时报错
纠正:将方法改为属性
syntaxEroor:invalid syntax
原因:语法错误
AttributeError:xxx object has no attribute xxx
原因:该对象中无此属性
TypeError:xxx object is not iterator
原因:所访问的对象并非为”迭代器“
将迭代对象转换为迭代器
FileNotFoundError:File xxxx does not exist
原因:文件xxxx没找到。可能写错了文件名,或者文件不存在 ”当前目录中”
IndexError:too many indices for array
原因:索引下标的维度超出了其该对象的定义中给出的维数
改用切片的方式
TypeError:Required argumengt xxxx not found
原因:在方法/函数的调用中没有给出必选形式参数对应的实际参数的值
TypeError:an xxxx is required(got type yyyy)
原因:对象的类型有误
错误提示的含义为:此处需要的是xxxx类型的对象,而给出的是YYYY类型
纠正方法:检查拼写是否有误,如果不是拼写有误。建议进行强制类型转换或者换成另外一个函数。
ValueError:Wrong number of items passed xxxx,placement implies YYYY
原因:代码中给出的items个数是XXX,但解释器需要的个数是YYYY
按照解释器要求调整items的个数
#以上内容均来自《python 编程从数据分析到数据科学》