How do I set a property in python using its string name

Posted by dave on Stack Overflow See other posts from Stack Overflow or by dave
Published on 2010-06-16T13:37:00Z Indexed on 2010/06/16 13:42 UTC
Read the original article Hit count: 202

Filed under:

Hey, here's a dumb question: how can I set an object property given its name in a string. I have a dictionary being passed to me and I wish to transfer its values into namesake properties using code like this:

    for entry in src_dict:
          if entry.startswith('can_'):
              tgt_obj[entry] = src_dict_profile[entry]

I'm still a bit of a noob with Python so would appreciate some help. - dave.

© Stack Overflow or respective owner

Related posts about python