Andreas Pfrengle wrote:
> # Accessing db (see http://www.djangoproject.com/documentation/db-api/):
> myobj = MyModel.objects.get(<some filter>)
> var = myobj.vector
> # vector is a Textfield, so var now contains a string, naming another 
> db-field of myobj
> 
> execstr = "attr = myobj." + var
> exec execstr
> # attr now contains the content of the field named in var (an int in my 
> case)

Use
attr = getattr(myobj, var)

> attr += 42    #some calculation with attr
> 
> execstr = "myobj." + var + " = attr"
> exec execstr

setattr(myobj, var, attr)

Kent
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to