gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:48:25 25 4
gpt4 key购买 nike

在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com