0

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])
    file.close()
    print(poswords)
    # TODO`

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

1 Answer 1

0

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.

2
  • 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
    Commented Nov 9, 2017 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
    – user19621
    Commented Nov 9, 2017 at 19:55

You must log in to answer this question.

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