Hi

Have a look at Expando as a base class for starters.
http://code.google.com/appengine/docs/python/datastore/expandoclass.html

And also you should avoid using exec/eval,

use setattr and getattr http://docs.python.org/library/functions.html#setattr

e.g.

setattr(myobj,'my_property_name',some_value)  - have a

Rgds

T



On Apr 7, 10:31 pm, J <j.si...@earlystageit.com> wrote:
> I need to assign a value to a Model property but its name is not known
> until runtime. For illustrative purposes, say
>
> class Story(db.Model):
>     title = db.StringProperty()
>     body = db.TextProperty()
>
> s = Story(title="The Three Little Pigs")
>
> Since I wanted to decide on the property name at runtime, I wrote:
> cmd = 's.%s = %s' % ('body', '"Once upon a time..."')
> exec(cmd)
>
> I shouldn't have to use exec. There has to be a better way of
> assigning values to properties.
>
> Any suggestions?

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to