python 包名中包含数字是否可以接受?

Is it acceptable to have python package names with numbers in it?

我见过 PyPI 发行版名称以及 python 包含数字的包名称。例如 flake8 是一个示例,您还可以使用 import flake8.

导入

根据 PyPI 和 PEP 标准,包名中可以包含数字吗?我知道出于语法原因您不能以数字开头,但从标准的角度来看,中间或结尾是否可以?

首先注意PyPI项目名和模块名是完全独立的;没有什么可以阻止您创建安装模块 bar 的软件包 foo,并且这两个名称在有效方面遵循不同的政策。

模块名称受 Python 语法的限制才有效 identifiers. In Python 2,这意味着它们必须由一个 ASCII 字母或下划线后跟零个或多个 ASCII 字母、数字、and/or下划线。在Python3中,加入了Unicode,事情变得更复杂了,但我相信所有的ASCII模块名称仍然遵循相同的限制。

PyPI 上的项目名称(如 PEP 508, among others) must consist entirely of ASCII letters, numbers, ., -, and/or _, and they must begin & end with a letter or number. There is also a normalization policy 中指定,强制不区分大小写并将 .-_ 的运行视为相等,所以 foo-barFOO.BAR 被认为是同一个项目。

此外,PEP 8 has a section on package and module names;它说:

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.

When an extension module written in C or C++ has an accompanying Python module that provides a higher level (e.g. more object oriented) interface, the C/C++ module has a leading underscore (e.g. _socket).

所以,是的,您可以在项目名称和模块名称中同时使用数字,项目名称甚至可以以数字开头!