Strategies for controling attribute assignment

Emile van Sebille emile at fenx.com
Tue Oct 2 10:43:51 EDT 2001


So, what you're trying to do is manipulate two dicts with one interface
_without_ needing to distinguish which dict is intended.  It seems to me
that even with a private/public scheme, you'll need to test _something_.
Why not try letting all the internals use a leading underscore and all the
database not, then test on that.

--

Emile van Sebille
emile at fenx.com

---------
"Dale Strickland-Clark" <dale at riverhall.NOSPAMco.uk> wrote in message >
> I thought this might be difficult to convey. This is typical of the
> approach I'm currently using:
>
> def __setattr__(self, field, value):
> if self._dbTable.has_key(field):
> self._dbTable[field].validate(value)
> self._fields[field] = value
> self._saved = 0
> else:
> self.__dict__[field] = value
>
> I have to distinguish between assignments to 'public' attributes
> (which will go in my database) and instance variables which are used
> throughout the class. I need to validate assignments to the database
> but just let everything else through.
>
> But it means that EVERY internal assignment to instance attributes
> needs to go through this code.
>
> I guess what I'm after is a distinction between private and public
> attrbutes.
>
> Does that make it any clearer?
> --
> Dale Strickland-Clark
> Riverhall Systems Ltd




More information about the Python-list mailing list