Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Google应用程序引擎NDB检索浮点属性_Python_Google App Engine_Google Cloud Datastore - Fatal编程技术网

Python Google应用程序引擎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]

我很抱歉,如果这个问题有一个明显的解决办法,但我一直试图搜索一整天

我有一个非常简单的NDB模型:

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()

天哪,我真傻。承认花了我这么长时间,我很伤心!非常感谢:-)别担心,小事情总是最难发现的。