Will python never intend to support private, protected and public?

Fredrik Lundh fredrik at pythonware.com
Thu Sep 29 16:59:01 CEST 2005


Steve Holden wrote:

> To avoid naming conflicts, Python provides a mechanism (name mangling)
> which pretty much guarantees that your names won't conflict with anybody
> else's, *even if you subclass a class whose methods use the same name*.

as long as you don't cheat, that is:

# your code

class Secret:
    def __init__(self):
        self.__hidden = "very secret value"

# my code

from yourcode import Secret

class Secret(Secret):
    def gethidden(self):
        return self.__hidden

s = Secret()
print s.gethidden()

</F> 






More information about the Python-list mailing list