Read and Write Unicode UTF-8 Files in Python



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)
Updated on: 2020-02-20T07:59:19+05:30

28K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements