프로그램
[파이썬] 문제 : text파일 읽고 수정해서 다른 파일로 저장
오디세이99
2022. 11. 22. 13:30
728x90
반응형
(문제)
텍스트 파일에서 일부를 지운 뒤 새로운 파일을 생성하여 수정한 것만 나타내는 문제 입니다.
문제는 - "ex_lec02_input.txt" 파일에서 "대한미디어" 출판사의 책을 삭제하고 "ex_lec02_output.txt" 로 저장하세요.
이고 "ex_lec02_input.txt" 은 아래 사진 첨부
(방법)
read_file = open('C:/Users/admin/Desktop/ex_lec02_input.txt', 'r')
write_file = open('C:/Users/admin/Desktop/ex_lec02_output.txt', 'a')
for line in read_file:
if line.find("대한미디어") != -1:
continue
write_file.write(line)
write_file.close()
read_file.close()
728x90
반응형