Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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 如何将StringProperty作为字符串对象进行迭代?_Python_String_Python 2.7_Google App Engine_Webapp2 - Fatal编程技术网

Python 如何将StringProperty作为字符串对象进行迭代?

Python 如何将StringProperty作为字符串对象进行迭代?,python,string,python-2.7,google-app-engine,webapp2,Python,String,Python 2.7,Google App Engine,Webapp2,我的代码如下: class sample(ndb.Model): text=ndb.StringProperty() class sample2(webapp2.RequestHandler): def get(self, item): q = sample.query() q1 = query.filter(item in sample.text) 我想在示例内的文本中搜索特定的单词(项)。我该怎么做呢?我尝试了这个链接,但它并没有真正回答我的问

我的代码如下:

class sample(ndb.Model):
    text=ndb.StringProperty()

class sample2(webapp2.RequestHandler):
   def get(self, item):
       q = sample.query()
       q1 = query.filter(item in sample.text)

我想在示例内的文本中搜索特定的单词(项)。我该怎么做呢?我尝试了这个链接,但它并没有真正回答我的问题-

首先,自2020年1月1日以来,谷歌云平台强烈鼓励用户使用更新的运行时。此外,不再推荐使用ndb库,并且在开始使用Python 3运行时之前,需要更新依赖ndb库的代码。所有这些原因让我建议你在花很多时间之前直接切换

话虽如此,您可以在ndb库文档中找到关于和的答案。本文中还有几个例子

首先,需要使用
query()
方法检索实体,然后通过python对象属性表示法访问其数据。大致如下所示:

q = sample.query()            # Retrieve sample entity.
substring = 'word' in q.text  # Returns True if word is a substring of text

不幸的是,您不能对数据存储(或任何其他数据库)执行类似的查询。数据存储查询基于索引,索引不能存储复杂的信息,例如字符串是否有某个子字符串


App Engine还有一个功能,您可以使用它来进行更复杂的文本搜索。

是的,您是对的。我问了一些人同样的疑问,他们说了同样的话,建议我使用文档和索引。