如何解决以下错误?
How to resolve the following error?
我正在阅读编程集体智慧中关于搜索引擎的章节,偶然发现了以下代码片段并尝试在 IPython 中实现它。但是,我遇到了错误:
def getmatchrows(self,q):
fieldlist='w0.urlid'
tablelist=''
clauselist=''
wordids=[]
words=q.split()
tablenumber=0
for word in words:
wordrow=self.con.execute("select rowid from wordlist where word='%s'" % word).fetchone()
if wordrow!=None:
wordid=wordrow[0]
wordids.append(wordid)
if tablenumber>0:
tablelist+=','
clauselist+=' and '
clauselist+='w%d.urlid=w%d.urlid and '%(tablenumber-1,tablenumber)
fieldlist+=',w%d.location'%tablenumber
tablelist+='wordlocation w%d'%tablenumber
clauselist+='w%d.wordid=%d'%(tablenumber,wordid)
tablenumber+=1
fullquery="SELECT %s FROM %s WHERE %s"%(fieldlist,tablelist,clauselist)
cur=self.con.execute(fullquery)
rows=[row for row in cur]
return row,wordids
我收到以下错误:
TypeError Traceback (most recent call last)
<ipython-input-25-e5fade95f22f> in <module>()
----> 1 e.getmatchrows('data analysis')
C:\Users\Blue\Anaconda\searchengine.pyc in getmatchrows(self, q)
128 tablelist+=','
129 clauselist+=' and '
--> 130 clauselist+='w%d.urlid=w%d.urlid and '%tablenumber- 1,tablenumber
131 fieldlist+=',w%d.location'%tablenumber
132 tablelist+='wordlocation w%d'%tablenumber
TypeError: unsupported operand type(s) for &: 'str' and 'tuple'
在第 130 行加上括号:
tablenumber-1,tablenumber>>(tablenumber1,tablenumber)
我正在阅读编程集体智慧中关于搜索引擎的章节,偶然发现了以下代码片段并尝试在 IPython 中实现它。但是,我遇到了错误:
def getmatchrows(self,q):
fieldlist='w0.urlid'
tablelist=''
clauselist=''
wordids=[]
words=q.split()
tablenumber=0
for word in words:
wordrow=self.con.execute("select rowid from wordlist where word='%s'" % word).fetchone()
if wordrow!=None:
wordid=wordrow[0]
wordids.append(wordid)
if tablenumber>0:
tablelist+=','
clauselist+=' and '
clauselist+='w%d.urlid=w%d.urlid and '%(tablenumber-1,tablenumber)
fieldlist+=',w%d.location'%tablenumber
tablelist+='wordlocation w%d'%tablenumber
clauselist+='w%d.wordid=%d'%(tablenumber,wordid)
tablenumber+=1
fullquery="SELECT %s FROM %s WHERE %s"%(fieldlist,tablelist,clauselist)
cur=self.con.execute(fullquery)
rows=[row for row in cur]
return row,wordids
我收到以下错误:
TypeError Traceback (most recent call last)
<ipython-input-25-e5fade95f22f> in <module>()
----> 1 e.getmatchrows('data analysis')
C:\Users\Blue\Anaconda\searchengine.pyc in getmatchrows(self, q)
128 tablelist+=','
129 clauselist+=' and '
--> 130 clauselist+='w%d.urlid=w%d.urlid and '%tablenumber- 1,tablenumber
131 fieldlist+=',w%d.location'%tablenumber
132 tablelist+='wordlocation w%d'%tablenumber
TypeError: unsupported operand type(s) for &: 'str' and 'tuple'
在第 130 行加上括号:
tablenumber-1,tablenumber>>(tablenumber1,tablenumber)