passing variables as object attributes

Nitin Pawar nitinpawar432 at gmail.com
Mon Aug 16 09:53:39 EDT 2010


you would need to define a class first with its attiributes and then you may
want to initiate the variables by calling the class initilializer

On Mon, Aug 16, 2010 at 7:10 PM, Vikas Mahajan <vikas.mahajan12 at gmail.com>wrote:

> 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Nitin Pawar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100816/a8a82a5f/attachment.html>


More information about the Python-list mailing list