专用模块的命名约定 [英] Naming convention for private modules

查看:80
本文介绍了专用模块的命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个模块中有多个内部功能.由于模块太大,因此我想将这些内部函数分解为同一软件包中单独的实用程序"模块.实用程序模块将仅包含程序包内部函数,不应将其视为程序包公共API的一部分.这样的内部模块是否有公认的命名约定?

I have multiple internal functions in a module. Because the module is getting too large, I want to factor out these internal functions into a separate "utility" module in the same package. The utility module would only contain package-internal functions which should not be considered part of the package's public API. Is there an accepted naming convention for such internal modules?

直觉上,我在模块名称前加了下划线.但是,这是C/C ++模块的命名约定根据PEP8 .

Intuitively, I'd prefix the module name with an underscore. However, that is the naming convention for C/C++ modules according to PEP8.

如果函数位于单独的模块中,则仅在函数名称前加下划线前缀是不正确的(就像我到目前为止所做的那样)(因为在这种情况下,下划线指的是模块级别的隐私).

Simply prefixing the function names with an underscore (as I did until now) doesn't seem right if the functions are in a separate module (because the underscore in that case refer to module-level privacy).

推荐答案

我不会说带前缀的下划线专门适用于C/C ++扩展模块.相反,此类模块通常不打算直接使用,而是为同名的Python模块提供了私有实现(请参见socket/_socket).按照这种逻辑,我不明白为什么任何非公开使用的模块(无论是用C还是Python实现)都不应该使用_前缀.

I wouldn't say that a prefixed underscore applies exclusively to C/C++ extension modules. Rather, such a module is not often intended to be used directly, but provides a private implementation for a Python module of the same name (cf. socket/_socket). By that logic, I don't see why any module not intended for public use (whether implemented in C or Python) should not use the _ prefix.

这篇关于专用模块的命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆