Best way to control assignment to attribute?
Aahz
aahz at pythoncraft.com
Wed Feb 4 14:18:27 EST 2004
In article <XF9Ub.175053$6y6.3406052 at bgtnsc05-news.ops.worldnet.att.net>,
wes weston <wweston at att.net> wrote:
>Frank Millman wrote:
>>
>> I want to control the assignment of a value to an attribute. Instead
>> of allowing it to be changed directly, I want to enforce that a method
>> is called, which will perform the assignment subject to various
>> checks.
>
> See __slots__; not sure if there's a newer/better way.
You should be certain before even thinking of suggesting __slots__.
__slots__ is intended only to save memory; there are many problems with
using it if you don't know what you're doing.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code --
not in reams of trivial code that bores the reader to death." --GvR
More information about the Python-list
mailing list