应该使用哪个:python- <module>或<module> -python?</module> </module>

时间:2014-02-23 20:50:57

标签: python naming-conventions python-module

创建Python模块/库时,应该使用哪种命名约定?我见过像python-requests这样的项目,然后是mysql-python之类的项目。 python应该是模块名称的前缀还是后缀?采用/推荐的方式更多?

1 个答案:

答案 0 :(得分:0)

official Python style guide一般不鼓励使用长名称,如果需要标点符号,则应使用下划线而不是连字符。就后缀或前缀而言,两者都不是必需的,但两者都是可接受的。在这两者中,使用“Py”作为前缀可能是最常见的。例如,PyQuerypy2appPyX

以下是PyPi上提供的43,000多个软件包列表中的一些数据:

+-----------------------------------------------+-------+--------+
| Neither starts nor ends with 'Py' or 'Python' | 37943 | 87.40% |
+-----------------------------------------------+-------+--------+
| Starts with 'Py'                              |  3639 | 8.38%  |
+-----------------------------------------------+-------+--------+
| Starts with 'Python'                          |   814 | 1.88%  |
+-----------------------------------------------+-------+--------+
| Ends with 'Py'                                |   796 | 1.83%  |
+-----------------------------------------------+-------+--------+
| Ends with 'Python'                            |   219 | 0.50%  |
+-----------------------------------------------+-------+--------+