Re: Adding properties to an instance

2008-02-07 Thread dg . google . groups
> > Does this mean that __setattr__ > > incurs the same performance penalty that overriding __getattribute__ > > would? > > Not quite AFAICT - there's less going on here. Also, getting an > attribute is (usually at least) more common than setting it. > > > Possibly I can live with this because I th

Re: Adding properties to an instance

2008-02-07 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : >> As a side note: the naming symetry between __getattr__ and __setattr__ >> is a gotcha, since __setattr__ is mostly symetric to __getattribute__ - >> IOW, customizing __setattr__ is a bit tricky. The naive approach, ie: > > Ah I see - so __setattr__ is called immediat

Re: Adding properties to an instance

2008-02-07 Thread dg . google . groups
> As a side note: the naming symetry between __getattr__ and __setattr__ > is a gotcha, since __setattr__ is mostly symetric to __getattribute__ - > IOW, customizing __setattr__ is a bit tricky. The naive approach, ie: Ah I see - so __setattr__ is called immediately whereas __getattr__ is only cal

Re: Adding properties to an instance

2008-02-07 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > On Feb 6, 11:09 pm, "[EMAIL PROTECTED]" > <[EMAIL PROTECTED]> wrote: >> While this is technically possible (I tried a couple years ago), it >> requires hacking the __getattribute__ method, which is something I >> would not recommand, not only because it can be tricky,

Re: Adding properties to an instance

2008-02-06 Thread dg . google . groups
On Feb 6, 11:09 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > While this is technically possible (I tried a couple years ago), it > requires hacking the __getattribute__ method, which is something I > would not recommand, not only because it can be tricky, but mostly > because this is a very

Re: Adding properties to an instance

2008-02-06 Thread dg . google . groups
On Feb 6, 10:54 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > I'd suggest a small improvement: _A as a class name isn't very nice. > Replace the inner class statement with: > _A = type(self.__class__.__name__ + '_autoprops', (self.__class__,), {}) Ah yes, that's much nicer. > A problem wit

Re: Adding properties to an instance

2008-02-06 Thread [EMAIL PROTECTED]
On 6 fév, 21:06, [EMAIL PROTECTED] wrote: > Hi all, > > So I understand that properties belong to a class not an instance, but > nonetheless I want to add properties to an instance. While this is technically possible (I tried a couple years ago), it requires hacking the __getattribute__ method, wh

Re: Adding properties to an instance

2008-02-06 Thread Gabriel Genellina
En Wed, 06 Feb 2008 18:06:48 -0200, <[EMAIL PROTECTED]> escribió: > So I understand that properties belong to a class not an instance, but > nonetheless I want to add properties to an instance. I have a class > which when an instance is created runs some fairly complicated code > and produces a

Re: Adding properties to an instance

2008-02-06 Thread Jared Grubb
Er, instead of "getattr(self,...) you gotta do "object.__getattr__(self,...)" and same for setattr and delattr. Dumb error on my part. (Otherwise you get infinite recursion!) On Feb 6, 2008 12:43 PM, Jared Grubb <[EMAIL PROTECTED]> wrote: > Here's one way of doing what you're asking... I would su

Re: Adding properties to an instance

2008-02-06 Thread Jared Grubb
Here's one way of doing what you're asking... I would suggest using __getattribute__ and __setattr__ to dispatch the methods to the custom class you invent that holds all those properties. For example (I simplified your makeprops into __init__ just to keep the example short, but you can probably s

Adding properties to an instance

2008-02-06 Thread dg . google . groups
Hi all, So I understand that properties belong to a class not an instance, but nonetheless I want to add properties to an instance. I have a class which when an instance is created runs some fairly complicated code and produces a set of names which I'd like to be able to access via properties. At