Why self?

Fredrik Lundh fredrik at pythonware.com
Thu Jul 11 19:55:19 EDT 2002


string.join(list("-%s-" % random.choice(teams))) wrote:

> No, you are only using a convention to let other developers know
> that these variables are private - the python interpreter does not
> even attempt to hide a '__' variable from other classes or code.

class Spam:
    def __init__(self):
        self.__private = 1
    def get(self):
        return self.__private

x = Spam()

print x.get()
print x.__private

$ python test.py
1
Traceback (most recent call last):
  File "test.py", line 10, in ?
AttributeError: Spam instance has no attribute '__private'

</F>





More information about the Python-list mailing list