Python 异常错误
IndentationErrorIndentationError
代码缩进不正确,而缩进在 Python 中具有语法意义。
python
查看详情 AttributeError对象不具有所请求的属性或方法。
尝试访问对象上不存在的属性或方法。对象可能在预期为其他类型时为 None,方法名可能拼写有误,或使用了错误的类型。
使用 type(obj) 检查对象类型。访问前使用 hasattr(obj, 'attr') 进行检查。对可能为 None 的对象添加空值检查。使用 dir(obj) 列出可用属性。查阅类的文档。
None.split() # AttributeError: 'NoneType' has no attribute 'split'IndentationError代码缩进不正确,而缩进在 Python 中具有语法意义。
Model.DoesNotExist使用 .get() 执行 Django ORM 查询时,未找到匹配记录。
KeyboardInterrupt用户按下 Ctrl+C 中断了正在运行的程序。
pickle.UnpicklingErrorpickle 模块无法反序列化提供的数据。
IndexError序列索引超出了给定序列的有效范围。
StopIteration由 next() 函数抛出,表示迭代器中没有更多元素。