Encoding an o/p file in python as ANSI

  ansi, encoding, python-3.x, utf-8

I want the output of my file to be encoded as ANSI instead of the uft-8 input file.
I have tried the code below:

file= open(path_dm, "r", encoding=’ANSI’)

lines = file.readlines()

file.close()

#STEP 2

lines1=lines[0]

n=60

seq2=[lines1[i:i+n] for i in range(0, len(lines1), n)]

#seq2

with open(path_out, ‘w’, encoding=’ANSI’) as f:
for item in seq2:
f.write("%sn" % item)

Source: Python-3x Questions

LEAVE A COMMENT