
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to 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)
- Related Articles
- Convert Unicode to UTF-8 in Java
- Convert UTF-8 to Unicode in Java
- How to represent Unicode strings as UTF-8 encoded strings using Tensorflow and Python?
- How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters in java?
- Read and write WAV files using Python (wave)
- Read and write tar archive files using Python (tarfile)
- Read and write AIFF and AIFC files using Python (aifc)
- How to read text files using LINECACHE in Python
- How to Read and Writes Files in Ruby
- How can Tensorflow text be used to split the UTF-8 strings in Python?
- How to read and parse CSV files in C++?
- Difference Between ANSI and UTF-8
- UTF-8 Validation in C++
- How to read CSV files in Golang?
- How to convert an MySQL database characterset and collation to UTF-8?

Advertisements