get/set

Greg Weeks weeks at vitus.scs.agilent.com
Tue May 14 15:35:10 EDT 2002


William Dode (wilk at flibuste.net) wrote:
: 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 ?

Putting aside __getattr__, __setattr__, __getattribute__, properties, and
__slots__, then whether or not you define get/set methods is a matter of
style, just as in Java and C++.  As in Java and C++, I consider it to be
good style.

Greg

PS: As for the slew of additional possibilities mentioned in the previous
paragraph: <sarcasm>Python is still nicer than Perl, so it is of the utmost
importance that more constructs be added to allow us to do the same things
(or marginally different things) in new ways.  We should strive to make our
2.2 code as unique and foreign to 1.5.2 style as humanly possible.  More
constructs!  Terser code!  TIMTOWTDI!</sarcasm>



More information about the Python-list mailing list