다음 코드를 작성하여 압축 된 디렉토리의 텍스트 파일을 읽습니다. 출력을 바이트로 원하지 않기 때문에 출력을 문자열로 표시하기 위해 TextIOWrapper를 추가했습니다. Zip 파일을 줄 단위로 읽는 올바른 방법이라고 가정하면 (그렇지 않은 경우) 출력이 빈 줄을 인쇄하는 이유는 무엇입니까? 그것을 제거 할 수있는 방법이 있습니까?TextIOWrapper가있는 python zipfile 모듈
import zipfile
import io
def test():
zf = zipfile.ZipFile(r'C:\Users\test\Desktop\zip1.zip')
for filename in zf.namelist():
words = io.TextIOWrapper(zf.open(filename, 'r'))
for line in words:
print (line)
zf.close()
test()
>>>
This is a test line...
This is a test line...
>>>
The two lines in the file inside of the zipped folder are:
This is a test line...
This is a test line...
고마워요!