본문 바로가기
파이썬

파이썬 How to delete all blank lines in the file with the help of python?

by º기록 2020. 12. 14.
반응형

예를 들어 다음과 같은 파일이 있습니다.

첫 번째 줄
second line

세 번째 줄

결과적으로 우리는 다음을 얻어야합니다.

첫 번째 줄
second line
세 번째 줄

Python 만 사용

 

해결 방법

 

import fileinput
for line in fileinput.FileInput("file",inplace=1):
    if line.rstrip():
        print line

 

참조 페이지 https://stackoverflow.com/questions/2369440

 

 

반응형

댓글