I want to write an encoded text to a file using Python 3.6, the issue is that I want to write it as a string and not as bytes.
text = open(file, 'r').read()
enc = text.encode(encoding) # for example: "utf-32"
f = open(new_file, 'w')
f.write(str(enc)[2:-1])
f.close()
The problem is, I still get the file content as bytes (e.g. the '\n' remains the same instead of become a new row).
I also tried to use:
enc.decode(encoding)
but it's just returning me back the old text I had in the first place.
any ideas how can I improve this piece of code?
Thanks.