passing variables as object attributes

Vikas Mahajan vikas.mahajan12 at gmail.com
Mon Aug 16 09:40:06 EDT 2010


Hello to all

I am new to python. I am facing problem to use variables as object
attributes. I have to use loop and dynamically add attributes to a
object and for this purpose I have to use variables with object names.

For example-:
Let us say object car has an attribute engine, then
varname = "engine"
car.varname = "dummy value"
is giving me Error: object car does not have attribute varname.

Please tell me how can I use variables as objects attributes.

Thanks.



More information about the Python-list mailing list