Python ファイル読み込み

Pythonでファイル読み込みをするサンプルです。


コマンドラインで実施する場合は、事前に「test.txt」が配置しているディレクトリへ移動しておくこと。

# -*- coding: utf-8 -*-
f = open('test.txt', 'r')
# 読み込んだ情報を出力
for row in f:
    print(row)

f.close()

test.txtのファイル内容
1

実行結果
2


Bookmark this on Yahoo Bookmark
Bookmark this on Google Bookmarks
Share on LinkedIn
LINEで送る
Pocket

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

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