1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

一番簡単なFile読込。

import os
import sys
import re
# ファイル名
data_file_name = 'my_test.txt'
f = open(data_file_name, 'r')#ファイル読み込み
str = f.read()
f.close()
my_list_in2=str.split("\n")

print(my_list_in2)#各行は配列に収められている。

with を使わないのが特徴です。
my_list_in2=['1','','3','']の様な物も読み込めます。

最後に改行を入れず書けます。
if my_list_in2[3]==''
my_list_in2[3]='4'

strw = "\n".join(my_list_in2)
print('myjyoin',strw)
f = open("mytest2.txt", 'w')#ファイル書込み
f.write(strw)
f.close()
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?