英文:
Why are some Python exceptions lower-case?
问题
在Python中,异常是类并且被命名为类的方式。例如:OSError
。
然而,有一些异常,比如在socket模块中的异常,它们的命名是小写的。例如:socket.timeout
,socket.error
。
为什么会这样呢?
英文:
In Python, exceptions are classes and cased as such. For example: OSError
.
However, there are some exceptions, such as those in the socket module, that are named in lower-case. For example: socket.timeout
, socket.error
.
Why is this?
答案1
得分: 7
根据文档,
异常 socket.error 是 OSError 的不推荐别名。
从版本 3.3 开始:根据 PEP 3151,此类别名已变为 OSError。
PEP 3151 中提到
虽然标准异常类型位于根命名空间中,但它们的可视区别在于它们使用 CamelCase 命名约定,而几乎所有其他内置类型都使用小写命名(除了 True、False、None、Ellipsis 和 NotImplemented)。
英文:
According to the docs,
> 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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论