1
0

Pythonメモ

Posted at

概要

Pythonでなにかしらを書いているときに、よく調べたりしていたちょっとした処理をまとめます。

ファイル処理

ファイルの読み込み、書き込みについてまとめます。

ファイル書き込み

# ファイルに書き込む文字列
s = 'test string'
# ファイル名
path = 'test_write.txt'

# ファイルに書き込む処理
with open(path, mode='w') as f:
    f.write(s)

ファイル読み込み

# ファイル名
path = 'test_write.txt'

# ファイルから読み込む処理
with open(path) as f:
    s_read = f.read()

    # 読み込んだ内容を表示
    print(s_read)
1
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
1
0