Python: CSVファイルの読み込み – csv.readerオブジェクト

Sponsored Link

このエントリーをはてなブックマークに追加
はてなブックマーク - Python: CSVファイルの読み込み – csv.readerオブジェクト
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Livedoor Clip
Bookmark this on Yahoo Bookmark

ソースコード

#!/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,aki
2,hiro
3,norika
4,kaede

実行結果

<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>

リファレンス

関連すると思われる記事:

Sponsored Link

This entry was posted in Python and tagged , , , . Bookmark the permalink.

Facebook comments:

3 Responses to Python: CSVファイルの読み込み – csv.readerオブジェクト

  1. Pingback: train_boy

  2. Pingback: python ism

  3. Pingback: yone

コメントを残す

メールアドレスが公開されることはありません。

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>