Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I start internal methods with _?

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 __?

like image 364
RomaValcer Avatar asked Oct 23 '25 08:10

RomaValcer


1 Answers

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. E.g. from 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 (inside class FooBar, __boo becomes _FooBar__boo).

so be aware of that fact.

like image 170
Dimitris Fasarakis Hilliard Avatar answered Oct 24 '25 22:10

Dimitris Fasarakis Hilliard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!