Search code examples
pythonansi

How to set encoding as 'ANSI' using Python?


I am using Python 3.7.4 version. I want to set the encoding as 'ANSI' at the time of reading a text file and also writing a text file.

I another case I read a file by providing 'utf-8' ( please find code snippet below ) as encoding but in case of 'ANSI' I am not finding any value to provide as encoding.

code snippet :

content = open(fullfile , encoding='utf-8').readlines()  

What should be done to set encoding as 'ANSI' in Python ?


Solution

  • ANSI is not actually an encoding, you probably mean Windows-1252, which Python supports as 'cp1252'.