ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#!/usr/bin/python # coding: UTF-8 # CSVファイルの読み込み import csv filename = "table01.csv" csvfile = open(filename) print csvfile for row in csv.reader(csvfile): print row # 1行のリスト for elem in row: print elem, # 行の中の要素 print csvfile.close() print csvfile |
CSVファイル (table01.csv) (番号,名前)
1 2 3 4 |
1,aki 2,hiro 3,norika 4,kaede |
実行結果
1 2 3 4 5 6 7 8 9 10 |
<open file 'table01.csv', mode 'r' at 0x01BECCC8> ['1', 'aki'] 1 aki ['2', 'hiro'] 2 hiro ['3', 'norika'] 3 norika ['4', 'kaede'] 4 kaede <closed file 'table01.csv', mode 'r' at 0x01BECCC8> |
コメント
http://tinyurl.com/ydcv97j
Python: CSVファイルの読み込み – csv.readerオブジェクト – Yukun's Blog
http://twitter.com/train_boy/statuses/6298328658 "http://tinyurl.com/ydcv97j
Python: CSVファイルの読み込み – csv.readerオブジェクト – Yukun's Blog"
yokotaへ→http://www.yukun.info/blog/2008/06/python-csv-read.html