Python 异常错误
IndentationErrorIndentationError
代码缩进不正确,而缩进在 Python 中具有语法意义。
python
查看详情 TypeError: object is not subscriptable对不支持索引操作的对象使用了方括号([])。
对未实现 __getitem__ 的对象使用了方括号。常见情况:变量为 None、整数或其他不支持索引的类型。
索引前检查对象类型。添加 None 检查:if obj is not None: obj[0]。确认变量是预期类型(list、dict、string)。使用类型注解和类型检查工具尽早发现此类错误。
None[0] # TypeError: 'NoneType' object is not subscriptableIndentationError代码缩进不正确,而缩进在 Python 中具有语法意义。
ChildProcessError子进程操作失败。
TimeoutError阻塞操作期间发生了系统级超时。
AttributeError对象不具有所请求的属性或方法。
IsADirectoryError对一个目录路径执行了文件操作。
pickle.UnpicklingErrorpickle 模块无法反序列化提供的数据。