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
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
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'
>>
>
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,
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