PEP8中的模块名称

2024-10-03 13:17:13 发布

您现在位置:Python中文网/ 问答频道 /正文

根据PEP8(或另一个著名的约定),如果python模块包含一个类,我是否可以将其命名为MyCoolClass?在

class MyCoolClass:
    ...

它应该只使用这个模块来导入这个类,其他什么都不导入。如果没有,那么命名模块的最佳方式是什么?在

请提供必要的证明链接。在


Tags: 模块证明链接方式命名classpep8mycoolclass
1条回答
网友
1楼 · 发布于 2024-10-03 13:17:13

从Python软件基金会网站(关于PEP8):

对于模块

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.

对于类

Class names should normally use the CapWords convention.

针对您的特定情况

如果你的类名为Foo,那么你将把你的模块称为“Foo”,全部小写。有关命名约定和其他样式建议的更多信息,请参见PEP 8,Python样式指南。在

相关问题 更多 >