LoginSignup
0
0

More than 5 years have passed since last update.

【備忘録】ファイル読み込み ~Python~

Posted at

ファイルの読み込み方法

今更といえば今更なこと。
今までファイルの読み込みを以下のように行っていた。

f = open("hoge.txt", mode='r')
様々な処理
f.close()

上記のように'open'をそのまま使ってもいいが、'with'をともに用いることでプログラムが以上終了した際でも、読み込み途中のファイルが自動で閉じられる。

with open("hoge.txt", mode='r') as f
    様々な処理

備忘録程度に・・・

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0