Assignment not the same as defining?

Steve Holden sholden at holdenweb.com
Wed Oct 3 08:41:13 EDT 2001


"Dale Strickland-Clark" <dale at riverhall.NOSPAMco.uk> wrote in message
news:a70mrt441n8h5bh0sf88rhae2q85v6g4hh at 4ax.com...
> "Steve Holden" <sholden at holdenweb.com> wrote:
>
[Dale explains failure to rebind __setattr__()]
> >>
> >From Python 2.0 Reference Manual, section 3.3.2:
> >"""
> >The following methods can be defined to customize the meaning of
attribute
> >access (use of, assignment to, or deletion of x.name) for class
instances.
> >For performance reasons, these methods are cached in the class object at
> >class definition time; therefore, they cannot be changed after the class
> >definition is executed.
> >"""
> >
> >foiled-by-an-optimization-ly y'rs  - steve
>
> Thanks Steve. What a handy chap you are to have around

A pleasure. Always ready to help anyone who didn't download the manuals with
their Python distribution <0.75 wink> - seriously, all I did was to look up
__setattr__ in the manual!

>
but can I just
> eject a heartfelt *BOLLOCKS* on this one?
>
Certainly! But never mind the bollocks, here's the Sex Pistols ...

> Now I need yet another cludge.

Perhaps it's one of those times when your design has wandered just a little
too far up a blind alley, and you now feel constrained by something which
needn't exist if you went back a little and took another, possibly only
slightly different, direction. Not, you understand, that I'm saying I *know*
enough about your current design to be sure on this, simply that I recognise
the signs of frustration from my own experiences. To summarise (or
summarize, as they say over here):

a) You've got these whizzy __setattr__() methods that distinguish between
persistent attributes and "ordinary" ones, applying verification to the
former but not the latter. You are prepared to put up with the overhead
because it makes things easier for client software to set all instance
attributes in the same way.

b) Your __setattr__() method is expensive/special enough that you don't
really want it to be activated until after you've run the __init__ method.

c) Python optimizes the snot out of __setattr__ access (along with the other
magic methods) , so it won't let you do what you want to do.

Over to you: either there's some other obvious solution you've failed to
spot, or you will come back with other questions that will help you to
*find* a better non-obvious solution. Go to it!

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list