bz2 module

Alex Martelli aleaxit at
Tue Oct 19 09:45:11 CEST 2004

Brad Tilley <bradtilley at> wrote:
> >>AttributeError: 'module' object has no attribute 'BZ2File'
> > 
> > Looks like your Python is misinstalled, or something...:
> > 
> >>>>import bz2
> >>>>bz2.BZ2File
> > 
> > <type 'bz2.BZ2File'> this is the first thing you should investigate...

> >>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 =
> >     if not data: break
> >     destination.write(data)
> > 
> > destination.close()
> > source.close()

"You're welcome", by the way.

> >>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...
> 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.

Touchy, aren't we?  Bet you took the part about sneaking in at night &c
at literal value too -- after all, there was no smiley, so I clearly
must be in deadly earnest rather than deadpanning a friendly ribbing.

The answer, turned back to serious mood, means: if something is missing
in the docs it's because people who think it should be there have not
submitted a doc patch for it.  I'm not comfortable with the library
*reference* being full of examples; I think it should probably be split
into a reference (a real one) and a collection of how-to/tutorials (with
the examples).  So, I've submitted doc pathes for correction of errors,
omissions, imperfect or ambiguous phrasing, etc, but not ones for the
addition of examples.

The most _systematic_ collection of examples of use of the standard
library is neither of my books, btw, but rather Lundh's "Standard Python
Library" book -- it's a bit dated, but it has examples of use of _every_
module that was in the library when the book was written.


More information about the Python-list mailing list