Python implements psuedo-private methods by munging method names that start with two underscores but don't end with underscores. It Just adds the class name to the front.
>>> class Foo(object):
... def __private(self):
... print('secret')
...
>>> dir(Foo)
['_Foo__private', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
Notice the _Foo__private
method name. You can just call that name.
>>> Foo()._Foo__private()
secret
Things get weird with inheritance. Notice below that the subclass has two private methods. Subclasses need to be aware of the munging not to be surprised. If you use a private method you may find you mess up anyone who inherits from the class and still wants to work with your code.
>>> class Bar(Foo):
... def __private(self):
... print('secret 2')
...
>>> dir(Bar)
['_Bar__private', '_Foo__private', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
Private methods are not part of an implementor's public interface and may be changed at any time without violating the public interface. You can use them, but be aware that all hack rules apply.