python - 为什么有些 Python 异常是小写的?

标签 python python-3.x

在 Python 中,异常是类,并且也是如此。例如:OSError .

但是,也有一些异常(exception),例如 socket module 中的异常(exception)情况。 ,以小写形式命名。例如:socket.timeout , socket.error .

这是为什么?

最佳答案

根据文档,

exception socket.error A deprecated alias of OSError.

Changed in version 3.3: Following PEP 3151, this class was made an alias of OSError.

PEP 3151 says

while standard exception types live in the root namespace, they are visually distinguished by the fact that they use the CamelCase convention, while almost all other builtins use lowercase naming (except True, False, None, Ellipsis and NotImplemented)

关于python - 为什么有些 Python 异常是小写的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59617184/

相关文章:

python - 如何让 python 进程保持事件状态——正确的方法

python - 如何确定 struct.unpack 的格式(因为我没有用 Python 打包)?

python - Pandas 基于最后一个值的合并函数

python - paramiko:打开和返回 sftp 连接的方法

python - 非默认 shell 命令的子进程

python - 在 Red Hat 上使用 MySQL 连接器安装 Python

python-3.x - 使用 psycopg2 调用带有自定义类型数组的 postgres 函数

django - 如何使用 Celery 和 Django 将任务路由到不同的队列

python - 不一致的 SignatureDoesNotMatch Amazon S3 与 django-pipeline、s3boto 和存储

python - 尝试使用正则表达式在 python 中删除字符 EM DASH "—"(—)