How to read and write unicode (UTF-8) files in Python?

PythonServer Side ProgrammingProgramming

The io module is now recommended and is compatible with Python 3's open syntax: The following code is used to read and write to unicode(UTF-8) files in Python

Example

import io
with io.open(filename,'r',encoding='utf8') as f:
    text = f.read()
# process Unicode text
with io.open(filename,'w',encoding='utf8') as f:
    f.write(text)
raja
Published on 11-Jan-2018 22:19:43
Advertisements