I just started working on the sentiments, at the moment I'm loading the positive words into a list and printing them out at a test. I'm having trouble with the for loops for getting each word into the list, my code is: `

def __init__(self, positives, negatives):
    """Initialize Analyzer."""
    poswords = []
    i = 0
    file = open("positive-words.txt","w")
    for words in positive-words.txt:
        poswords = poswords.append(positive-words.txt[i])
    # TODO`

I probably did a bit of this wrong, but any help is appreciated


You should be getting an error in the for loop because you don’t have any variable that’s called positive_words.text

Also remember that the text files have some comments inside quotation marks at the beginning of the file, make sure NOT to “load” those comments into your list.

| improve this answer | |
  • How do I make it into the variable? What should be the value? I'm not sure how I link the text file to the analyzer file – Joel Banks Nov 9 '17 at 19:00
  • Look up how the open method works and pay attention to what it returns. When you create successfully a list with the words in the file, that list will become an instance variable, just check out how to call instance variables – Luis César Nov 9 '17 at 19:55

You must log in to answer this question.

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