get/set
Alex Martelli
aleax at aleax.it
Sat May 11 06:02:17 EDT 2002
Mark McEahern wrote:
> [William Dode]
>> coming from java, i use to do a lot of get set method and make all the
>> variable as private.
>>
>> class Toto:
>> def getA(self): return self._a
>> def setA(self,v): self._a=v
>> ...
>>
>> Shall i do like that in python ?
>
> Field descriptors are new with Python 2.2
Yes.
> and require the new-style
> classes.
No.
>>> class X:
... def getTer(self): return 23
... def setTer(self, value): pass
... ter = property(getTer, setTer)
...
>>> x = X()
>>> x.ter
23
Alex
More information about the Python-list
mailing list