I am writing one file :
with open("test_%s.tem" %i, "w") as f1:
....
f1.close()
I want to convert the encoding to UCS-2 little endian format. Is it possible to do this in open() or close() functions. Any ideas would help.
I am writing one file :
with open("test_%s.tem" %i, "w") as f1:
....
f1.close()
I want to convert the encoding to UCS-2 little endian format. Is it possible to do this in open() or close() functions. Any ideas would help.
In Python 3
, according to documentation in :https://docs.python.org/3/library/functions.html#open
you can specify the encoding with the encoding parameter.
with open("test_%s.tem" %i, "w", encoding="utf16") as f1:
On Python 2 you can use codecs.open with the encoding parameter.
If you use Python 3 just use the encoding parameter of open.
UCS-2 is a subset of UTF-16, so try to use 'UTF-16'
as the parameter value.