Naming convention for private modules

孤街醉人 提交于 2019-12-11 03:24:17

问题


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?

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).


回答1:


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.




回答2:


Not as far as I know, but there are some things seen often:

  • Module named internal or internal_xyz
  • Subpackage named internal containing internal modules
  • Underscore, even though it's meant for C modules. I, personally, prefer this one for it's shortness and because everyone knows what it means.


来源:https://stackoverflow.com/questions/26278185/naming-convention-for-private-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!