Skip to content

Instantly share code, notes, and snippets.

@liuzhuan
Last active August 29, 2015 14:10
Show Gist options
  • Save liuzhuan/b500fc10b1e629e2d875 to your computer and use it in GitHub Desktop.
Save liuzhuan/b500fc10b1e629e2d875 to your computer and use it in GitHub Desktop.
Python read UTF-8 text file
# -*- 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
@liuzhuan
Copy link
Author

liuzhuan commented Dec 9, 2014

If in Python 2.X version,
you can use
import codecs
codecs.open("data.txt", "r", encoding="utf-8-sig")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment