bz2 module

Brad Tilley bradtilley at gmail.com
Mon Oct 18 22:18:11 CEST 2004


I'm having a bit of trouble using the bz2 module. The documentation for 
it is very poor. Here's what I'm trying to do:

import bz2

x = file('test.bkf', 'rb')

while True:
         data = x.read(1024000)
         if not data:
                 break
         bz2.BZ2File('test.bkf.copy', 'w').write(data)

x.close()

It fails with this error:
AttributeError: 'module' object has no attribute 'BZ2File'

Can anyone give me an example of how to use bz2 to compress files. Why 
don't the docs give examples of this?!?

Thanks,
Brad






More information about the Python-list mailing list