Stu Richards
Stu Richards

Reputation: 141

UnidecodeDecode when reading .txt file

This may be a very basic fix, but I've dived through every example online trying to sort this out. I'm loading in a text file with Python 3.4 like so:

text = open("/Users/Stu/python/extext.txt")
text = unidecode(text)
text = open(text, "r").read()

and then I get thrown this error:

Traceback (most recent call last):
  File "/Users/Stu/Twitter Python/Victoria.py", line 46, in <module>
    short_pos = unidecode(short_pos)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/unidecode/__init__.py", line 37, in unidecode
    for char in string:
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf3 in position 4645: ordinal not in range(128)

I'm assuming that it's finding a character that it can't decode, but all there is in this doc is english and basic punctuation. Any support you guys could give would be greatly appreciated.

Cheers!

Upvotes: 0

Views: 262

Answers (1)

Stu Richards
Stu Richards

Reputation: 141

This seemed to allow me to read the text:

short_pos = open("/Users/Stu/Twitter Python/short_reviews/positive1.txt","r", encoding = "latin-1").read()

Thanks for everyone's support!

Upvotes: 1

Related Questions