moar confuse()

>>> class Foo:
...     def __init__(self, start):
...             self.__bar = start
...     def bar(self):
...             return self.__bar
...     def setBar(self, neo):
...             self.__bar = neo
... 
>>> f = Foo(42)
>>> f.bar()
42
>>> f.__bar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: Foo instance has no attribute '__bar'
>>> f.__bar = "ougaouga"
>>> f.__bar
'ougaouga'
>>> f.bar()
42
>>> f.setBar(1337)
>>> f.__bar
'ougaouga'
>>> f.bar()
1337
>>> f.__bar = "wtf"
>>> f.bar()
1337

Publié par kAworu Ven 15 jan 2010 19:33:00 GMT


Commentaires

Réagir à ce billet

laisser un commentaire