[Tutor] Getting/setting attributes
Steven D'Aprano
steve at pearwood.info
Wed Sep 22 00:28:51 CEST 2010
On Wed, 22 Sep 2010 07:06:50 am lists wrote:
> As I understand it, it makes most sense to set/get the attribute of
> an object using a method rather than doing it directly.
Heavens no!!! That's backwards!
It might be justified in languages like Java, where you can't easily
change your mind about direct attribute access. There's also a school
of thought that disapproves of direct attribute access for a number of
philosophical reasons, but if you strongly agree with that philosophy
you'll probably find Python isn't a good language for you. (It has to
do how much the compiler should forbid the programmer from doing, and
how much software reliability that buys you.)
90% of the time, stick to direct attribute access, especially for short
scripts and pre-release versions of software. If and only if you find
that too limiting, or perhaps not limiting enough, then change to using
getter and setter functions and properties.
--
Steven D'Aprano
More information about the Tutor
mailing list