Toby SegaranによるプログラミングのCollective Intelligenceによるこのコード部分は、私を少し混乱させました。 python2で書かれているsqliteのselect文は、forループで(urlid、)とそれ以降(リンカ)に取得するイテレータを返します。なぜこの構文を使用するのか分かりません。目的は何ですか?どうもありがとう。Forループのタプルと反復子Python
for i in range(iterations):
print "Iteration %d" % (i)
for (urlid,) in self.con.execute('select rowid from urllist'):
pr=0.15
# Loop through all the pages that link to this one
for (linker,) in self.con.execute(
'select distinct fromid from link where toid=%d' % urlid):
# Get the PageRank of the linker
linkingpr=self.con.execute(
'select score from pagerank where urlid=%d' % linker).fetchone()[0]
単一要素のタプルを扱う、それはカンマを覚えておくことが重要です。それがなければ '(urlid)'があります。これは '(urlid、)'が単一要素のタプルである間に 'urlid'だけを残す式をラップするために括弧を使用しています。 –
ええ、私の記事の最後の文です。 –