Problem with Property
Peter Hansen
peter at engcorp.com
Sat Feb 25 09:11:33 EST 2006
"none <"@bag.python.org wrote:
> I'm trying to implement a simple repeateable property mechansism so I
> don't have to write accessors for every single instance variable I have.
...
> Any ideas?
Yes, don't write accessors for every single instance variable you have.
In some languages that might be appropriate, or considered good style.
In Python, it's entirely unnecessary and you should just access
instance variables directly when you want to, and in the odd case where
you want to do something more than set/get/del them you can resort to
properties (when a nice clear method wouldn't fit).
(Sorry not to answer the question directly. If you feel you really need
to use accessors then go ahead, but I just wanted you to know that many
Python programmers feel quite differently about them than, say, C++ or
Java programmers might.)
-Peter
More information about the Python-list
mailing list