How to write data by dynamic parameter name

Posted by Maxim Welikobratov on Stack Overflow See other posts from Stack Overflow or by Maxim Welikobratov
Published on 2011-11-25T17:34:05Z Indexed on 2011/11/25 17:50 UTC
Read the original article Hit count: 250

Filed under:
|

I need to be able to write data to datastore of google-app-engine for some known entity. But I don't want write assignment code for each parameter of the entity. I meen, I don't want do like this

val_1 = self.request.get('prop_1')
val_2 = self.request.get('prop_2')
...
val_N = self.request.get('prop_N')
item.prop_1 = val_1
item.prop_2 = val_2
...
item.prop_N = val_N
item.put()

instead, I want to do something like this

args = self.request.arguments()
  for prop_name in args:
    item.set(prop_name, self.request.get(prop_name))
item.put()

dose anybody know how to do this trick?

© Stack Overflow or respective owner

Related posts about python

Related posts about google-app-engine