Should I start a helper function with underscore(s)?
本问题已经有最佳答案,请猛点这里访问。
在一个模块中,我应该使用一个、两个或没有下划线来表示用户不应该调用的助手函数吗?
python样式指南pep-8建议使用一个前导下划线。
The following special forms using leading or trailing underscores are recognized (these can generally be combined with any case convention):
_single_leading_underscore : weak"internal use" indicator. E.g.from M import * does not import objects whose name starts with an underscore.- ...
可能只有一个下划线,但这取决于具体情况。
具体来说,python风格指南(pep 8)指出:
_single_leading_underscore: weak"internal use" indicator. E.g. from M import * does not import objects whose name starts with an underscore.
__double_leading_underscore: when naming a class attribute, invokes name mangling (inside class FooBar, __boo becomes _FooBar__boo; see below).
另请参阅此问题以获得更长的答案:对象名称前的单下划线和双下划线的含义是什么?