Read. Check. Write. A Broken Python script
Question: I am developing a word game, and for this game, I needed a list of words.
Sadly, this list was _so_ long that I just had to refine it (this list of
words can be found on any Mac at **/usr/share/dict/**).

To refine it, I decided to use my own Python scripts. I already wrote a script
before that removes all words that start with capital letters (thus removing
names of places, etc.), and it worked. This is it:

    
    
    with open("/Users/me/Desktop/oldwords.txt", "r") as text:
        with open("/Users/me/Desktop/newwords.txt", "w") as towriteto:
            for word in text:
                if word[0]==word[0].lower():
                    towriteto.write(word)
    

Then, I decided to refine it even further; I decided that I would delete all
words that are not in the pyenchant module English dictionary. This
opperation's code is very similar to the previous one's code. This is my code:

    
    
    import enchant
    with open("/Users/me/Desktop/newwords.txt", "r") as text:
        with open("/Users/me/Desktop/words.txt", "w") as towriteto:
            d = enchant.Dict("en_US")
            for word in text:
                if d.check(word):
                    towriteto.write(word)
    

Sadly, this did not write anything to the "towriteto" file, and after some
debugging, I found that

    
    
    d.check(word) -> False
    

It always returned false. However, when I checked words separately, real words
returned True, and fake words returned False as they should.

I have no idea what is wrong with my second script. The file locations are
correct and the pyenchant installation had no issues.

Thanks in advance!


Answer: I don't know the input file format but if there is only one word per line, try
to remove the end-of-line character of `word` before to call `d.check(word)`:

    
    
    word = word.rstrip()
    

