在我正在编写的Python Google App Engine应用程序中,我有一个存储在数据存储区中的实体,我需要检索它,制作它的精确副本(除了密钥),然后将此实体放回去.
我该怎么做?特别是,在做这个时我是否需要注意任何警告或技巧,以便获得我期望的那种副本而不是其他东西.
ETA: 嗯,我试了一下,确实遇到了问题.我想以这样的方式制作我的副本,以便在编写代码时不必知道属性的名称.我的想法是这样做:
#theThing = a particular entity we pull from the datastore with model Thing
copyThing = Thing(user = user)
for thingProperty in theThing.properties():
copyThing.__setattr__(thingProperty[0], thingProperty[1])
Run Code Online (Sandbox Code Playgroud)
执行时没有任何错误......直到我尝试从数据存储中提取copyThing,此时我发现所有属性都设置为None(显然除了用户和密钥).很明显,这段代码正在做一些事情,因为它正在用None替换默认值(所有属性都设置了默认值),但根本不是我想要的.建议?