Python Can';t摆脱TypeError:';str';对象不可调用
我正试图在ipython笔记本上制作/训练一个twitter情绪分析器,但有一段代码存在严重问题:Python Can';t摆脱TypeError:';str';对象不可调用,python,string,object,callable,Python,String,Object,Callable,我正试图在ipython笔记本上制作/训练一个twitter情绪分析器,但有一段代码存在严重问题: import csv #Read the tweets one by one and process it inpTweets = csv.reader(open('SampleTweets.csv', 'rb'), delimiter=',', quotechar='|') tweets = [] for row in inpTweets: sentiment = row[0]
import csv
#Read the tweets one by one and process it
inpTweets = csv.reader(open('SampleTweets.csv', 'rb'), delimiter=',', quotechar='|')
tweets = []
for row in inpTweets:
sentiment = row[0]
tweet = row[1]
processedTweet = processTweet(tweet)
featureVector = getFeatureVector(processedTweet, stopwords)
tweets.append((featureVector, sentiment));
#end loop
我得到一个错误:
TypeError回溯(最近一次调用)
在()
7=第[0]行
8推特=行[1]
---->9 processedTweet=processTweet(tweet)
10 featureVector=getFeatureVector(ProcessedWeet,stopwords)
11条tweets.append((featureVector,情绪));
TypeError:“str”对象不可调用
而且帮助真的很棒,谢谢 这里您的processedTweet应该是一个
str
,因此您不能调用它
示例-
>>> a = 'apple'
>>> a(0)
Traceback (most recent call last):
File "<pyshell#212>", line 1, in <module>
a(0)
TypeError: 'str' object is not callable
processTweet
在您显示的代码中未定义。谢谢!对不起,我是个白痴……但我该怎么办呢?我不知道你的api,你需要检查你的processedTweet
,它应该有一个错误,或者你需要以不同的方式使用它。它看起来需要处理你的推文,所以你应该在某处使用它作为函数。但是,我还是不知道这是如何实现的。希望这有帮助。@RachelDbbs,如果有帮助,你可以投票并接受答案。谢谢。
>>> a = 'apple'
>>> a(0)
Traceback (most recent call last):
File "<pyshell#212>", line 1, in <module>
a(0)
TypeError: 'str' object is not callable
>>> a[0]
'a'