I am running a simple code to replace a word with another in my files like so:
import random
import os
path = '/path/of/file/'
files = os.listdir (path)
for file in files:
with open (path + file) as f:
newText = f.read().replace('Plastic Ba','PlasticBag')
with open (path + file, "w") as f:
f.write(newText)
And in doing so I get an error that I have never encountered before :
Traceback (most recent call last):
File "replaceText.py", line 9, in <module>
newText = f.read().replace('Plastic Ba', 'PlasticBag')
File "/Users/vivek/anaconda3/lib/python3.6/codecs.py", line 321, 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
I am not sure what this means or what the mistake here is? I have run this script multiple times in the past without any issues. Any help on resolving this would be great!