Python标准库中类名的大写标准是什么? [英] What is the capitalization standard for class names in the Python Standard Library?
问题描述
Python标准库类的规范似乎是类名是小写的-对于诸如str
和int
之类的内置组件以及作为标准库模块一部分的大多数类,这似乎适用必须导入的内容,例如datetime.date
或datetime.datetime
.
The norm for Python standard library classes seems to be that class names are lowercase - this appears to hold true for built-ins such as str
and int
as well as for most classes that are part of standard library modules that must be imported such as datetime.date
or datetime.datetime
.
但是,某些标准库类(例如enum.Enum
和decimal.Decimal
)被大写.乍一看,类的名称等于模块名称时,似乎将其大写,但并非在所有情况下都适用(例如datetime.datetime
).
But, certain standard library classes such as enum.Enum
and decimal.Decimal
are capitalized. At first glance, it might seem that classes are capitalized when their name is equal to the module name, but that does not hold true in all cases (such as datetime.datetime
).
Python标准库中类名的大写约定背后的原理/逻辑是什么?
What's the rationale/logic behind the capitalization conventions for class names in the Python Standard Library?
推荐答案
关键资源<开发人员指南的/a>部分列出了 PEP 8 作为样式指南.
摘自PEP 8命名约定,重点是我的.
From PEP 8 Naming Conventions, emphasis mine.
Python库的命名约定有点混乱,因此 我们将永远无法获得完全一致的结果-不过,这是 当前推荐的命名标准.新模块和软件包 (包括第三方框架)应写给这些 标准,但是如果现有图书馆的风格有所不同, 首选内部一致性.
The naming conventions of Python's library are a bit of a mess, so we'll never get this completely consistent -- nevertheless, here are the currently recommended naming standards. New modules and packages (including third party frameworks) should be written to these standards, but where an existing library has a different style, internal consistency is preferred.