[New-bugs-announce] [issue32035] Documentation of zipfile.ZipFile().writestr() fails to mention that 'data' may also be bytes

Daniel report at bugs.python.org
Wed Nov 15 09:54:20 EST 2017


New submission from Daniel <daniel.niccoli at gmail.com>:

The documentation for "ZipFile.writestr(zinfo_or_arcname, data[, compress_type])" says: "Write the string data to the archive; [...]"
--> https://docs.python.org/3/library/zipfile.html

I fails to mention that data could also be bytes.

The source code does mention it however, that is how I found out:

def writestr(self, zinfo_or_arcname, data, compress_type=None):
        """Write a file into the archive.  The contents is 'data', which
        may be either a 'str' or a 'bytes' instance; if it is a 'str',
        it is encoded as UTF-8 first.
        'zinfo_or_arcname' is either a ZipInfo instance or
        the name of the file in the archive."""

I believe this should be added to the documentation as it's an important information to those who try to add non-UTF8 StringIO data to in-memory ZipFiles using BytesIO.

----------
assignee: docs at python
components: Documentation
messages: 306271
nosy: Daniel5148, docs at python
priority: normal
severity: normal
status: open
title: Documentation of zipfile.ZipFile().writestr() fails to mention that 'data' may also be bytes
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32035>
_______________________________________


More information about the New-bugs-announce mailing list