2,042 views
この記事は最終更新から 2392日 が経過しています。
まずは、Pythonを使ってテキストファイルを作成する。
>>> fh = open('data.txt','w') >>> fh.write('hello\n') >>> fh.write('see you!\n') >>> fh.close() >>> [user@dog-server]$ ls data.txt [user@dog-server]$ [user@dog-server]$ cat data.txt hello see you!
次に、作成したファイルを Pythonで読み込む。
>>> fh = open('data.txt','r') >>> >>> data = fh.read() >>> data 'hello\nsee you!\n' >>> >>> print data hello see you! >>> >>> ary = data.split('\n') >>> ary ['hello', 'see you!', ''] >>> ary[0] 'hello' >>> ary[1] 'see you!'
アクセス数(直近7日): ※試験運用中、BOT除外簡易実装済2026-05-08: 0回 2026-05-07: 0回 2026-05-06: 0回 2026-05-05: 0回 2026-05-04: 0回 2026-05-03: 1回 2026-05-02: 0回