gzip — Easy Playground
Read and write gzip-compressed files
Python Playground
import gzip
data = b"Hello " * 100
compressed = gzip.compress(data)
print(f"Original: {len(data)} bytes")
print(f"Compressed: {len(compressed)} bytes")
print(f"Ratio: {len(compressed)/len(data):.1%}")
decompressed = gzip.decompress(compressed)
print(f"Decompressed matches: {decompressed == data}")
Output
Click "Run" to execute your code
The gzip module is part of Python's standard library. Read and write gzip-compressed files.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?