[Tutor] Accessing class attributes: use methods only?
Bob Gailer
bgailer at alum.rpi.edu
Tue Feb 13 22:03:17 CET 2007
Chris Lasher wrote:
> Is it general good practice to access and set class attributes via
> methods only, or is it okay practice to directly interact with class
> attributes? The professor in a class on Perl that I'm taking suggested
> that directly accessing and setting class attributes was a bad idea.
> Just wondering what the current preference in Python is.
>
I really like the simplicity of a.b = 3. I groan when put in other
environments where a method call is required.
And Python has the magic method __setattr__ to intercept attribute
assignment for the times where some inspection / protection /
side-effect action is desired.
--
Bob Gailer
510-978-4454
More information about the Tutor
mailing list