0

そのため、特定の条件に応じてデータベースを通過する try/except ブロックを設定しました。

try:
    for searchnumber in itertools.count(0):
        print searchnumber
        c.execute("""SELECT words from searchterms where onstate = 1 AND progid = %d;""") % searchnumber
        searchterms = (c.fetchall())
        searchterms = [",".join(x) for x in searchterms]
        print searchterms
except:
    pass

何らかの理由で、progid を反復処理していません。実際、割り当てられた最初の値 (0) を取得していません。これはなぜでしょうか?私の知る限り、%d は searchnumber の整数値に置き換える必要があります

4

2 に答える 2

7

You're probably hiding a TypeError because you're trying to use the % operator on whatever object or value is equivalent to c.execute("string"). You might've caught it if you hadn't hidden all errors with the bare except. You'll note this is a specific antipattern in the official Python Dos and Don'ts page.

于 2012-07-12T03:17:10.900 に答える
5
  1. Never use except: pass, it hides information.

  2. The information it's currently hiding is probably a failure from this code:

     c.execute("""SELECT words from searchterms where onstate = 1 AND progid = %d;""") % searchnumber
    
于 2012-07-12T03:14:21.277 に答える