Re: [Tutor] setattr vs __setattr__

2010-09-06 Thread Rasjid Wilcox
On 7 September 2010 08:55, Steven D'Aprano wrote: > On Mon, 6 Sep 2010 09:03:30 pm Rasjid Wilcox wrote: >> I've been using >> >> for attr_name in name_list: >>     setattr(a, attr_name, getattr(b, attr_name)) >> >> to copy the attributes from one type of class to another, and it is >> not quite as

Re: [Tutor] setattr vs __setattr__

2010-09-06 Thread Steven D'Aprano
On Mon, 6 Sep 2010 09:03:30 pm Rasjid Wilcox wrote: > I've been using > > for attr_name in name_list: > setattr(a, attr_name, getattr(b, attr_name)) > > to copy the attributes from one type of class to another, and it is > not quite as readable as I would like. The one-liner in the for loop is

Re: [Tutor] setattr vs __setattr__

2010-09-06 Thread Rasjid Wilcox
On 6 September 2010 19:55, Hugo Arts wrote: > On Mon, Sep 6, 2010 at 9:27 AM, Rasjid Wilcox wrote: >> Hi all, >> >> Suppose we have >> >> class A(object): >>    pass >> >> a = A() >> >> Is there any difference between >> >> setattr(a, 'foo', 'bar) >> >> and >> >> a.__setattr__['foo'] = 'bar' >> >

Re: [Tutor] setattr vs __setattr__

2010-09-06 Thread Hugo Arts
On Mon, Sep 6, 2010 at 9:27 AM, Rasjid Wilcox wrote: > Hi all, > > Suppose we have > > class A(object): >    pass > > a = A() > > Is there any difference between > > setattr(a, 'foo', 'bar) > > and > > a.__setattr__['foo'] = 'bar' > Did you mean a.__setattr__('foo', 'bar')? That's the same thing,

[Tutor] setattr vs __setattr__

2010-09-06 Thread Rasjid Wilcox
Hi all, Suppose we have class A(object): pass a = A() Is there any difference between setattr(a, 'foo', 'bar) and a.__setattr__['foo'] = 'bar' other than syntax? And which is considered 'better' form in Python? Cheers, Rasjid. ___ Tutor mai