Re: Dynamic use of property() fails

2008-04-15 Thread Bruno Desthuilliers
Hrvoje Niksic a écrit : > Bruno Desthuilliers <[EMAIL PROTECTED]> > writes: > >>> However, if you know what you're doing, you can simply customize your >>> class's __getattribute__ to do what *you* want for your objects. >> >> But bear in mind that, beside possible unwanted side-effectn, you'll >

Re: Dynamic use of property() fails

2008-04-15 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: >> However, if you know what you're doing, you can simply customize your >> class's __getattribute__ to do what *you* want for your objects. > > > But bear in mind that, beside possible unwanted side-effectn, you'll > get a non-negligible performanc

Re: Dynamic use of property() fails

2008-04-15 Thread Bruno Desthuilliers
andrew cooke a écrit : > On Apr 15, 4:06 am, Bruno Desthuilliers [EMAIL PROTECTED]> wrote: > >> The canonical solution is to use a custom descriptor instead of a property: (snip code) > i tried code very similar after reading the first replies and found > that it did not work as expected on setti

Re: Dynamic use of property() fails

2008-04-15 Thread andrew cooke
OK, fixed my bug - it does work. Now sleep... Thanks again, Andrew -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamic use of property() fails

2008-04-15 Thread andrew cooke
ignore that - i was mistaken (my test was too complex). the problem seems to be that the attribute is deleted even though __delete__ is defined. i'll look at it tomorrow. thanks again, andrew On Apr 15, 4:50 am, andrew cooke <[EMAIL PROTECTED]> wrote: > i tried code very similar after reading

Re: Dynamic use of property() fails

2008-04-15 Thread andrew cooke
On Apr 15, 4:06 am, Bruno Desthuilliers wrote: > The canonical solution is to use a custom descriptor instead of a property: > > class Field(object): >def __init__(self, name, onchange): > self.name = name > self.onchange = onchange > >def __get__(self, instance, cls): > if

Re: Dynamic use of property() fails

2008-04-15 Thread Bruno Desthuilliers
Hrvoje Niksic a écrit : (snip) > As others explained, descriptors are called for descriptors found in > class attributes, not in ones in instance attributes. (snip) > However, if you know what you're doing, you can simply customize your > class's __getattribute__ to do what *you* want for your o

Re: Dynamic use of property() fails

2008-04-15 Thread Bruno Desthuilliers
andrew cooke a écrit : > Hi, > > This is my first attempt at new classes and dynamic python, so I am > probably doing something very stupid... After reading the how-to for > descriptors at http://users.rcn.com/python/download/Descriptor.htm I > decided I would make an object that returns attribut

Re: Dynamic use of property() fails

2008-04-15 Thread Hrvoje Niksic
andrew cooke <[EMAIL PROTECTED]> writes: > This is my first attempt at new classes and dynamic python, so I am > probably doing something very stupid... After reading the how-to for > descriptors at http://users.rcn.com/python/download/Descriptor.htm I > decided I would make an object that return

Re: Dynamic use of property() fails

2008-04-15 Thread Hrvoje Niksic
"Gabriel Genellina" <[EMAIL PROTECTED]> writes: > The "magic" happens when the descriptor is found in the *class*, not > in the instance. I think it's detailed in Hettinger's document. The document is wrong here: Alternatively, it is more common for a descriptor to be invoked automatical

Re: Dynamic use of property() fails

2008-04-14 Thread andrew cooke
[Gabriel:] > The "magic" happens when the descriptor is found in the *class*, not in > the instance. I think it's detailed in Hettinger's document. > Do you actually want "per-instance" defined properties? ah! ok. yes, you're right: i want instance values but class properties, so i'll rethink th

Re: Dynamic use of property() fails

2008-04-14 Thread Gabriel Genellina
En Mon, 14 Apr 2008 22:43:39 -0300, andrew cooke <[EMAIL PROTECTED]> escribió: > This is my first attempt at new classes and dynamic python, so I am > probably doing something very stupid... After reading the how-to for > descriptors at http://users.rcn.com/python/download/Descriptor.htm I > de

Dynamic use of property() fails

2008-04-14 Thread andrew cooke
Hi, This is my first attempt at new classes and dynamic python, so I am probably doing something very stupid... After reading the how-to for descriptors at http://users.rcn.com/python/download/Descriptor.htm I decided I would make an object that returns attributes on read, but on setting calls an