Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert encoding of a text file from utf-8 to ansi or unicode in python

I have a text file with utf-8 encoding. I want to change it's unicode to ANSI or unicode automatically in python. Is it possible? How can i do it?

like image 614
narges Avatar asked Jan 04 '23 21:01

narges


1 Answers

Try this

#read input file
with codecs.open('USERS.CSV', 'r', encoding = 'latin-1') as file:
lines = file.read()  

#write output file
with codecs.open('1_UserPython.CSV', 'w', encoding = 'utf_8_sig') as file:
file.write(lines)
like image 176
Alciomar Hollanda Avatar answered Jan 07 '23 11:01

Alciomar Hollanda