Skip to content

Instantly share code, notes, and snippets.

@squarednob
Created December 3, 2013 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squarednob/7768558 to your computer and use it in GitHub Desktop.
Save squarednob/7768558 to your computer and use it in GitHub Desktop.
pythonで日本語csvを読み込む問題。
#1 日本語のcsvファイルを読み込むには、unicodecsvを使う。
#これはcsvを読み込むときにutf-8化した後、出力でunicode化してくれるもの。
#目的のcsvをメモ等などで、utf-8で保存した後、以下で読み込む。
import unicodecsv
f = open("utf30.csv","rb")
r = unicodecsv.reader(f, encoding='utf-8')
row = r.next() #r.next()だけで、rowのインデックスにすべて入る。forループはいらない!
print row[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment