If I have an object that has several internal functions that are not exactly meant for outside calls. Should I always start them with _
or __
?
It is indicated by PEP-8 that you should use a single underscore to indicate that these should be of internal use:
In addition, 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. Egfrom M import *
does not import objects whose name starts with an underscore.
Double leading underscores can also be used but, those are subject to name mangling:
__double_leading_underscore
: when naming a class attribute, invokes name mangling (insideclass FooBar
,__boo
becomes_FooBar__boo
).
so be aware of that fact.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.