Re: Adding a list of descriptors to a class

2007-08-07 Thread Bruno Desthuilliers
Bob B. a écrit : > I've been playing with descriptors lately. I'm having one problem I > can't seem to find the answer to. I want to assign a descriptor to a > list of attributes. I know I should be able to add these somewhere in > the class's __dict__, but I can't figure out where. Here's some

Re: Adding a list of descriptors to a class

2007-08-07 Thread Bruno Desthuilliers
Marc 'BlackJack' Rintsch a écrit : > On Tue, 07 Aug 2007 09:25:32 -0700, Bob B. wrote: > > >>Ok, that "exec" is an ugly hack. There's gotta be someway to plop >>this straight into the class's __dict__ without doing that, but when I >>try adding self.__class__.__dict__[attr] = MyDesc(attr) in MyC

Re: Adding a list of descriptors to a class

2007-08-07 Thread Bob B.
> Probably the simplest thing is to just add the attributes after the > class body, e.g.:: > > >>> class MyClass(object): > ... pass > ... > >>> for attr in ['attr1', 'attr2']: > ... setattr(MyClass, attr, MyDesc(attr)) > ... > >>> c = MyClass() > >>>

Re: Adding a list of descriptors to a class

2007-08-07 Thread Steven Bethard
Bob B. wrote: > I've been playing with descriptors lately. I'm having one problem I > can't seem to find the answer to. I want to assign a descriptor to a > list of attributes. I know I should be able to add these somewhere in > the class's __dict__, but I can't figure out where. Here's some co

Re: Adding a list of descriptors to a class

2007-08-07 Thread Marc 'BlackJack' Rintsch
On Tue, 07 Aug 2007 09:25:32 -0700, Bob B. wrote: > Ok, that "exec" is an ugly hack. There's gotta be someway to plop > this straight into the class's __dict__ without doing that, but when I > try adding self.__class__.__dict__[attr] = MyDesc(attr) in MyClass's > __init__ method, I get the error:

Adding a list of descriptors to a class

2007-08-07 Thread Bob B.
I've been playing with descriptors lately. I'm having one problem I can't seem to find the answer to. I want to assign a descriptor to a list of attributes. I know I should be able to add these somewhere in the class's __dict__, but I can't figure out where. Here's some code: class MyDesc(obje