Last active
August 29, 2015 14:10
-
-
Save liuzhuan/b500fc10b1e629e2d875 to your computer and use it in GitHub Desktop.
Python read UTF-8 text file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
import io | |
lines = io.open("data.txt", "r", encoding="utf-8-sig").readlines() # windows | |
lines = io.open("data.txt", "r", encoding="utf-8").readlines() # linux |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If in Python 2.X version,
you can use
import codecs
codecs.open("data.txt", "r", encoding="utf-8-sig")