txt
파일의 각 행을 읽고 다른 행의 각 행을 인쇄하려고합니다.for 루프의 출력을 여러 파일에 작성하십시오.
How are you? I am good.
filename2.txt
이 가지고 : 등등
Wow, that's great.
와 나는 다음과 같은 내용을 가지고 filename1.txt
을 원하는 지금
How are you? I am good.
Wow, that's great.
This is a text file.
......
: 가정,이 같은 텍스트 파일을 .
내 코드는 다음과 같습니다
#! /usr/bin/Python
for i in range(1,4): // this range should increase with number of lines
with open('testdata.txt', 'r') as input:
with open('filename%i.txt' %i, 'w') as output:
for line in input:
output.write(line)
내가 모든 파일은 파일의 모든 라인을 겪고있다 얻고있다. 위에서 설명한대로 각 파일에 단 한 줄만 넣기를 원합니다.