summaryrefslogtreecommitdiffstats
path: root/Demo/zlib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-08-02 23:15:58 (GMT)
committerGeorg Brandl <georg@python.org>2010-08-02 23:15:58 (GMT)
commit2db2b8a17dd643fd48ae050404e2dacc40afacc9 (patch)
tree9cbdfe75e0f0270b421a17cfa21d2ac0a27fcb18 /Demo/zlib
parentfb3b12d0c0b134a60b552d9aa1e23c9d00bccacd (diff)
downloadcpython-2db2b8a17dd643fd48ae050404e2dacc40afacc9.zip
cpython-2db2b8a17dd643fd48ae050404e2dacc40afacc9.tar.gz
cpython-2db2b8a17dd643fd48ae050404e2dacc40afacc9.tar.bz2
Another demo that at least runs again.
Diffstat (limited to 'Demo/zlib')
-rwxr-xr-xDemo/zlib/zlibdemo.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/Demo/zlib/zlibdemo.py b/Demo/zlib/zlibdemo.py
index 52f71a0..40a36d4 100755
--- a/Demo/zlib/zlibdemo.py
+++ b/Demo/zlib/zlibdemo.py
@@ -13,9 +13,8 @@ def main():
filename = sys.argv[0]
print('Reading', filename)
- f = open(filename, 'rb') # Get the data to compress
- s = f.read()
- f.close()
+ with open(filename, 'rb') as f: # Get the data to compress
+ s = f.read()
# First, we'll compress the string in one step
comptext = zlib.compress(s, 1)
@@ -30,15 +29,15 @@ def main():
chunk = 256
compressor = zlib.compressobj(9)
decompressor = zlib.decompressobj()
- comptext = decomp = ''
+ comptext = decomp = b''
for i in range(0, len(s), chunk):
- comptext = comptext+compressor.compress(s[i:i+chunk])
+ comptext += compressor.compress(s[i:i+chunk])
# Don't forget to call flush()!!
- comptext = comptext + compressor.flush()
+ comptext += compressor.flush()
for i in range(0, len(comptext), chunk):
- decomp = decomp + decompressor.decompress(comptext[i:i+chunk])
- decomp=decomp+decompressor.flush()
+ decomp += decompressor.decompress(comptext[i:i+chunk])
+ decomp += decompressor.flush()
print('Progressive compression (level 9):')
print(' Original:', len(s), 'Compressed:', len(comptext), end=' ')