Hot answers tagged

5 votes
Accepted

pset6 tweets, analyze.py and application.py

Maybe a simple typo in tweets here score = analyzer.analyze(tweets), since you want to send one tweet at a time. Also, beware here: token.lower(). The lower method returns the string in lower case, ...
user avatar
4 votes

Error in pset6 API Key not set

Make sure you're running flask in the same terminal window in which you exported the keys.
user avatar
3 votes
Accepted

pset6 - tweets, get_user_timeline function

Try it without the '@' prefix. get_user_timeline calls twitter.lookup_user(). The example in the twitter API doc shows screen_name without the '@' in the example.
user avatar
3 votes
Accepted

Python. Can't understand this code

The [expression_using_X for X in Y] is evaluating expression_using_X for every X being an element of Y, and the [] make that list of expression values a Python list. squares = [x**2 for x in range(11)...
user avatar
  • 20.7k
2 votes
Accepted

Pset6 Tweets output score and color different to staff version

This line token.lower() does not change token to lower case, it returns a copy of token in lower case. You can either set something to that return value (as with word = token.lower()) and then test ...
user avatar
1 vote
Accepted

Sentiments "tweets" elif statement error

Looks like unbalanced parentheses in the line above the elif.
user avatar
1 vote
Accepted

pset6 sentiments tweets

The most serious error I see in the first view is on the next line: file = open(positives, "r") keep in mind that both positives and negatives are variables that are meant to be a (disordered) set ...
user avatar
  • 5,172
1 vote

PSET6/Sentiments/analyzer.py, tweets

This syntax if word.lower() in self.positives == True: is the problem. Use if word.lower() in self.positives (without the equality). I don't remember the exact evaluation/operator precedence rules ...
user avatar
1 vote
Accepted

pset6 tweets subtraction when word is negative doesn't work

elif text.lower() in self.neg_words: shouldn't that be token.lower()?
user avatar
  • 18.4k
1 vote
Accepted

I don't understant how TweetTokenizer works

TweetTokenizer is a class in the nltk.tokenize.casual module. When you use the name of the class as a function, like: tokenizer = TweetTokenizer() that function, in Object Oriented Languages, is ...
user avatar
  • 7,326
1 vote
Accepted

Why am I getting TypeError: expected string or buffer?

The problem is get_user_timeline because it returns a list of strings i.e you can't just pass it to the tokenize function. Instead you have to iterate over the strings and tokenize them seperatly.
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible