What use of these _ prefix members?

Peter Otten __peter__ at web.de
Sun Jan 10 13:34:52 EST 2016


Robert wrote:


> When I read a sample file from hmm learn package, which is on top of
> scikit-learn package, I see there are many member functions (prefix with
> '_') have no caller. That is, I don't see anything uses those functions.
> Below is a sample part from class GMMHMM(_BaseHMM):

I bet the caller is in the superclass _BaseHMM, like in the following made-
up example:

>>> class Base:
...     def __init__(self, x):
...         self._init(x)
...     def _init(self, x): print("do something with", x)
... 
>>> class Derived(Base):
...     def _init(self, x):
...         super()._init(x)
...         print("do something else with", x)
... 
>>> Derived(42)
do something with 42
do something else with 42
<__main__.Derived object at 0x7f8e6b3e9b70>





More information about the Python-list mailing list