When I tested tweets after implementing Analyzer.py, I found that it said that every single tweet was neutral (The twitter account I used was @realDonaldTrump). I believe it has something to do with my implementation of Analyzer, but I don't know if the problem is in init or analyze. Thanks in advance.

Here is my code:

// edited out per academic honesty

1 Answer 1


In analyze, shouldn't you use self.positives, and not open the files again?

Now to the real problems: .lstrip(" ") does not remove the line break at the end of the line, you could use .strip() instead to remove all kinds of whitespace at both ends.

  • When I change if lower_token in positives: to if lower_token in self.positives: and likewise for negatives, I still get all neutral results. Am I not changing it correctly? Commented Mar 16, 2017 at 13:32
  • Have you checked the content of self.positives and self.negatives? Also, you don't seem to close any files. Any file opened should be closed after use, as there is some information kept on all the open files.
    – Blauelf
    Commented Mar 16, 2017 at 13:40
  • Just realized you named your variable like the function parameter in the initialization. Have you renamed that one then? Parameters and variables should not have the same name.
    – Blauelf
    Commented Mar 16, 2017 at 13:42
  • Where would I check for self.positives and self.negatives? Before I exit init? Thanks so much by the way. I changed self.positives to self.poswords and likewise for self.negatives, by the way. :-) Commented Mar 16, 2017 at 13:58
  • Problem is not self.positives, but variable positives you use for the file handle. __init__ receives two strings, in the default code called positives and negatives, containing the file names for the positive/negative word lists. You could for example print some debug output, maybe the length of your lists, I'd do that at the end of __init__.
    – Blauelf
    Commented Mar 16, 2017 at 14:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .