bz2 module
Brad Tilley
bradtilley at gmail.com
Mon Oct 18 16:46:45 EDT 2004
Alex Martelli wrote:
> Brad Tilley <bradtilley at gmail.com> wrote:
>
>
>>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'
>
>
> Looks like your Python is misinstalled, or something...:
>
>
>>>>import bz2
>>>>bz2.BZ2File
>
> <type 'bz2.BZ2File'>
>
>
>>Can anyone give me an example of how to use bz2 to compress files. Why
>
>
> import bz2
> source = open('test.bkf', 'rb')
> destination = bz2.BZ2File('test.bkf.bz2', 'w')
>
> while True:
> data = source.read(1024000)
> if not data: break
> destination.write(data)
>
> destination.close()
> source.close()
>
>
>>don't the docs give examples of this?!?
>
>
> If the docs were perfect, who'd ever buy Python in a Nutshell, or the
> Python Cookbook? So I sneak in at night in the CVS repository and
> secretly sabotage them just enough, destroying, without leaving a trace,
> all the wonderful doc patches that people are submitting all the time,
> fixing problems rather than whining about them...
>
>
> Alex
I don't know enough about proper Python usage to submit doc patches, so
when I google and can't find an answer and none of my coworkers can
answer my question, I post here for help... I wouldn't call that
whining, but you're entitled to your opinion of my post.
If I were knowledgeable enough to submit doc pathces, I would do so.
Thank you,
Brad
More information about the Python-list
mailing list