Python Google应用程序引擎NDB检索浮点属性
我很抱歉,如果这个问题有一个明显的解决办法,但我一直试图搜索一整天 我有一个非常简单的NDB模型:Python Google应用程序引擎NDB检索浮点属性,python,google-app-engine,google-cloud-datastore,Python,Google App Engine,Google Cloud Datastore,我很抱歉,如果这个问题有一个明显的解决办法,但我一直试图搜索一整天 我有一个非常简单的NDB模型: class UserData(ndb.Model): value = ndb.FloatProperty 现在,如果实体不存在,我将使用以下命令添加实体。否则,现在我只记录它: features = json.loads(self.request.get("features")) for field in features: val = float(features[field]
class UserData(ndb.Model):
value = ndb.FloatProperty
现在,如果实体不存在,我将使用以下命令添加实体。否则,现在我只记录它:
features = json.loads(self.request.get("features"))
for field in features:
val = float(features[field])
key = ndb.Key("user", user, "model", "1", "param", field)
res = UserData.query(ancestor=key)
if res.count() > 0:
param = res.fetch()[0]
print "currentVal = " + str(param.value)
else:
newparam = UserData(parent=key)
newparam.value = 1.0
newparam.put()
添加值可以正常工作,但打印行会输出以下内容:
currentVal = <class 'google.appengine.ext.ndb.model.FloatProperty'>
currentVal=
感谢大家花时间提供帮助。您的字段定义错误:您需要实例化属性
class UserData(ndb.Model):
value = ndb.FloatProperty()
天哪,我真傻。承认花了我这么长时间,我很伤心!非常感谢:-)别担心,小事情总是最难发现的。