data = data2 = ""
with open('file2.txt', encoding='utf-8', mode='r') as fp:
data = fp.read()
with open('file2.txt', encoding='utf-8', mode='r') as fp:
data2 = fp.read()
data += "\n"
data += data2
with open('file3.txt', 'w') as fp:
fp.write(data)
So I saw this code in another question similar like this, and tried using it. But it didn't work, it kept giving me error like this:
Traceback (most recent call last):
line 45, in <module>
fp.write(data)
line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-5: character maps to <undefined>
Can someone explain me why it is not working and how to fix it?