0
a
을 file
및 b
의 첫 번째 줄로 만들려고합니다.파일에서 줄 가져 오기
이렇게하면 아무 것도 인쇄되지 않습니다.
f = open(filename)
line = f.readline().strip()
while line:
a = f.readline()
b = f.readline()
line = f.readline()
print(a)
print(b)
변수를 모두 읽는 것이 아니라 변수에 특정 줄을 지정하고자합니다.
가능한 중복 http://stackoverflow.com/questions/3277503/how-do-i-read-a -file-by-line-into-a-list) – McGrady
정말로 목록에 모든 줄을 추가하지 마십시오 – James
왜'while' 루프가 있습니까? 그게 뭐야? – jonrsharpe