Vote count:
0
This morning, I asked question about unicode encoding error. UnicodeDecodeError: invalid start byte
I got a error return which persists up to now. (error code is following)
for line in fi:
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/codecs.py", line 313, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 3131: invalid start byte
So far I couldn't figure it out why this problem is happening, but I found something really interesting.
I changed the directory of files and that error message is gone. When I set reading directory(readDir) to my external hard drive, where all of my raw data is saved, this code perfectly works. However if I set the laptop hard drive, where just part of my raw data is saved, it still gives me back the error message above.
So I wonder whether the directory of files may cause the error.
Code that I have been using is following:
for filename in os.listdir(readDir):
filename = os.path.join(readDir, filename)
for keyword in keywords:
outFileName = os.path.join(sortDir, keyword)
outFileName = outFileName+'.csv'
with open(filename, 'r') as fi, open(outFileName, "a") as fo:
for line in fi:
asked 24 secs ago
The Location of Directory and Unicode Error
Aucun commentaire:
Enregistrer un commentaire