Python 2.7 如何解决以下错误?
我在阅读《编程集体智能》中有关搜索引擎的章节时,遇到了下面的代码片段,并试图在IPython中实现它。但是,我遇到了一个错误:Python 2.7 如何解决以下错误?,python-2.7,machine-learning,Python 2.7,Machine Learning,我在阅读《编程集体智能》中有关搜索引擎的章节时,遇到了下面的代码片段,并试图在IPython中实现它。但是,我遇到了一个错误: def getmatchrows(self,q): fieldlist='w0.urlid' tablelist='' clauselist='' wordids=[] words=q.split() tablenumber=0 for word in words: wordrow=self.c
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'
TypeError回溯(最近一次调用)
在()
---->1 e.getmatchrows(“数据分析”)
getmatchrows(self,q)中的C:\Users\Blue\Anaconda\searchengine.pyc
128表格列表+=','
129小句列表+='和'
-->130子句列表+='w%d.urlid=w%d.urlid和'%tablenumber-1,tablenumber
131字段列表+=',w%d.位置“%tablenumber”
132 tablelist+='wordlocation w%d'%tablenumber
TypeError:&:'str'和'tuple'的操作数类型不受支持
将论文放在第130行:
tablenumber-1,tablenumber>>(tablenumber1,tablenumber)
在跟踪中,
%
后面没有括号,这正常吗?嘿,你否决了这个问题吗?