Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get rid of TypeError: 'str' object is not callable

I'm trying to make/train a twitter sentiment analyser in ipython notebook and am having serious problems with one section of code:

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

And I'm getting this error:


TypeError                                 Traceback (most recent call last)
<ipython-input-10-bbcb1b9f05f4> in <module>()
      7     sentiment = row[0]
      8     tweet = row[1]
----> 9     processedTweet = processTweet(tweet)
     10     featureVector = getFeatureVector(processedTweet, stopwords)
     11     tweets.append((featureVector, sentiment));

TypeError: 'str' object is not callable

And help would be seriously great, thanks!

like image 677
Rachel Dbbs Avatar asked Jan 27 '26 14:01

Rachel Dbbs


1 Answers

Here your processedTweet should be a str hence you can't call it.

Example -

>>> a = 'apple'
>>> a(0)

Traceback (most recent call last):
  File "<pyshell#212>", line 1, in <module>
    a(0)
TypeError: 'str' object is not callable

But when I use index, it's fine. Callable means you are using that as a function like sum etc.

>>> a[0]
'a'
like image 123
garg10may Avatar answered Jan 30 '26 04:01

garg10may