tags:

views:

26

answers:

2

Hello, Can anyone help me?

I have list of fields called 'allowed_fields' and I have object called 'individual'.
allowed_fields is sub set of individual. Now I want to run loop like this

for field in allowed_fields:
obj.field = individual.field

obj have same fields like individual. Do you have solution of my problem? I will thankful to you.

A: 

If each field is actually a string, you could try the following.
I renamed field to fieldname to better indicate that it is a string.

for fieldname in allowed_fields:
    setattr(obj, fieldname, getattr(individual, fieldname))
Thanks for quick response. I think, I can manage now.
sim
A: 

setattr(obj, fieldname, fieldvalue)

(see also getattr to retrieve at runtime)

Rolo
Thanks for quick response. I think, I can manage now.
sim