Private class and instance methods?

Erik Max Francis max at
Sat Mar 10 19:34:39 CET 2001

How often do people use methods beginning with __ in order to get some
amount of privacy with the automatic name mangling that occurs, to get
some kind of weak protection, with, say, accessor methods:

    class C:
        def __init__(self, x):
            self.__x = x

        def getX(self): return self.__x
        def setX(self, x): self.__x = x

[which would of course allow C.getX and C.setX to do something different
in the future]?

 Erik Max Francis / max at /
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Nothing is true -- all is permissible.
\__/ Hassan i Sabbah
    Product's Quake III Arena Tips /
 Tips and tricks from the absolute beginner to the Arena Master.

More information about the Python-list mailing list