수색…


소개

이 모듈은 GNU 프로그램 gzip과 gunzip처럼 파일을 압축하고 압축을 풀 수있는 간단한 인터페이스를 제공합니다.

데이터 압축은 zlib 모듈에 의해 제공됩니다.

gzip 모듈은 Python의 File Object를 모델로하는 GzipFile 클래스를 제공합니다. GzipFile 클래스는 gzip 형식의 파일을 읽고 씁니다. 자동으로 압축하거나 압축을 풀어 일반 파일 객체처럼 보이게합니다.

GNU zip 파일 읽기 및 쓰기

import gzip
import os

outfilename = 'example.txt.gz'
output = gzip.open(outfilename, 'wb')
try:
    output.write('Contents of the example file go here.\n')
finally:
    output.close()

print outfilename, 'contains', os.stat(outfilename).st_size, 'bytes of compressed data'
os.system('file -b --mime %s' % outfilename)

터미널을 통해 1gzip_write.py1.Run으로 저장하십시오.

$ python gzip_write.py

application/x-gzip; charset=binary
example.txt.gz contains 68 bytes of compressed data


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow