2014-07-14 35 views
0

我只是不明白爲什麼這不工作... 請幫助谷歌App Engine的蟒蛇循環不工作

在我的數據庫我有一個分配類 每個任務都有一個名稱屬性和標籤物業

基本上我試圖讓該看到一個搜索結果,如果搜索詞(一子)是在數據存儲

#Here I pull out all of the Assignments from the assignment class 
    res = db.GqlQuery("SELECT * FROM Assignment ORDER BY created DESC") 
    #Here I make a results list, to store the finished assignments in 
    results = [] 
    #This is a loop to go through all terms of the search 
    for t in terms: 
     #Here is a loop to go through all assignments per search term 
     for r in res: 
      #Here is why in the world does this not work... 
      #If I change it to "if 'd' in 'dog' and t not in results:", 
      #then it works.... 
      #but even when t is 'a' and r.name is 'aaa' it doesn't work 
      if t in r.name and t not in results: 
       results.append(r) 
      if r.tags: 
       if t in r.tags and t not in results: 
        results.append(r) 
    print results 

回答

1

的名稱或任何標記似乎你有t和代碼中混合了r。要麼你想查看和存儲r收集匹配分配:

for t in terms: 
    for r in res: 
     if t in r.name and r not in results: 
      results.append(r) 
     if r.tags: 
      if t in r.tags and r not in results: 
       results.append(r) 

或周圍的其他方法,查看和存儲t收集匹配的搜索字詞:

for t in terms: 
    for r in res: 
     if t in r.name and t not in results: 
      results.append(t) 
     if r.tags: 
      if t in r.tags and t not in results: 
       results.append(t) 
0
if t in r.name and r not in results: 
    results.append(r) 
if r.tags: 
    if t in r.tags and r not in results: 
    results.append(r)