George Sakkis wrote:
> On Nov 19, 7:44 pm, r0g <[EMAIL PROTECTED]> wrote:
>> Hi There,
>>
>> I know you can use eval to dynamically generate the name of a function
>> you may want to call. Can it (or some equivalent method) also be used to
>> do the same thing for the variables of a class e.g.
>>
>> class Foo():
>>   bar = 1
>>   gum = 2
>>
>> mylist = ['bar','gum']
>>
>> a = Foo()
>> for each in mylist:
>>   a.eval(each) = 999
>>
>> If so, what is the proper syntax/method for this.
> 
> for each in mylist:
>     setattr(a, each, 999)
> 
> 
> HTH,
> George

Thank you George!

Damn I love Python! :0D
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to