[docs] zlib documentation

Julien Baley julien.baley at gmail.com
Sat Nov 27 15:44:21 CET 2010


Hello,

in the page : http://docs.python.org/dev/py3k/library/zlib.html#module-zlib
as well as
http://docs.python.org/dev/py3k/tutorial/stdlib.html#data-compression

We see that zlib.compress receives a string. This doesn't work, as you can
see in the following example:
>>> import zlib
>>> s = 'witch which has which witches wrist watch'
>>> t = zlib.compress(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be bytes or buffer, not str

(directly copied from the doc). I don't know if this is a documentation
error or a bug from the function however. Some people indicate that the
string should be encoded first, and indeed, from the code above:
>>> t = zlib.compress(s.encode("utf-8"))
>>> len(t)
37


Cheers,

Julien
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20101127/bf0768b6/attachment.html>


More information about the docs mailing list