- I have a .txt file in UTF-16-LE encoding .
- I want to remove the headers(1st row) and save it in ANSI
- I can do it maually but i need to do that for 150 txt files EVERY day
- So i wanted to use Python to do it automatically.
But i am stuck , i have tried this code but it is not working ,produces an error :
*"return mbcs_encode(input, self.errors)[0]
UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character "*
filename = "filetochangecodec.txt"
path = "C:/Users/fallen/Desktop/New folder/"
pathfile = path + filename
coding1 = "utf-16-le"
coding2 = "ANSI"
f= open(pathfile, 'r', encoding=coding1)
content= f.read()
f.close()
f= open(pathfile, 'w', encoding=coding2)
f.write(content)
f.close()