티스토리 뷰

[파일쓰기]



with open("data.txt", "w") as f:
for i in range(10):
data = "{} line!\n".format(i)
f.write(data)





[파일읽기]


with open("data.txt", "r") as f:
while True:
line = f.readline()
if not line:
break
print(line)


한줄씩 읽기



with open("data.txt", "r") as f:
lines = f.readlines()
for line in lines:
print(line)


한번에 읽기




댓글