Sometimes, we want to read and write to Unicode (UTF-8) files in Python.
In this article, we’ll look at how to read and write to Unicode (UTF-8) files in Python.
How to read and write to Unicode (UTF-8) files in Python?
To read and write to Unicode (UTF-8) files in Python, we can use the io.open
function.
For instance, we write
import io
f = io.open("test", mode="r", encoding="utf-8")
to call io.open
with the path of the file to open, the permission mode
and the encoding
of the file.
We set the encoding
to 'utf-8'
to read the file as a Unicode file.
Conclusion
To read and write to Unicode (UTF-8) files in Python, we can use the io.open
function.