write(ﬁlename, [arcname, [compress_type]])
Write the ﬁle named ﬁlename to the archive, giving it the archive name arcname (by default, this will
be the same as ﬁlename, but without a drive letter and with leading path separators removed). If given,
compress_type overrides the value given for the compression parameter to the constructor for the new entry.
The archive must be open with mode ’w’ or ’a’ – calling write() on a ZipFile created with mode ’r’
will raise a RuntimeError. Calling write() on a closed ZipFile will raise a RuntimeError.
Note: There is no ofﬁcial ﬁle name encoding for ZIP ﬁles. If you have unicode ﬁle names, you must
convert them to byte strings in your desired encoding before passing them to write(). WinZip interprets
all ﬁle names as encoded in CP437, also known as DOS Latin.
Note: Archive names should be relative to the archive root, that is, they should not start with a path
Note: If arcname (or filename, if arcname is not given) contains a null byte, the name of the ﬁle in
the archive will be truncated at the null byte.
writestr(zinfo_or_arcname, bytes, [compress_type])
Write the string bytes to the archive; zinfo_or_arcname is either the ﬁle name it will be given in the archive,
or a ZipInfo instance. If it’s an instance, at least the ﬁlename, date, and time must be given. If it’s a
name, the date and time is set to the current date and time. The archive must be opened with mode ’w’ or
’a’ – calling writestr() on a ZipFile created with mode ’r’ will raise a RuntimeError. Calling
writestr() on a closed ZipFile will raise a RuntimeError.
If given, compress_type overrides the value given for the compression parameter to the constructor for the
new entry, or in the zinfo_or_arcname (if that is a ZipInfo instance).
Note: When passing a ZipInfo instance as the zinfo_or_acrname parameter, the compression method
used will be that speciﬁed in the compress_type member of the given ZipInfo instance. By default, the
ZipInfo constructor sets this member to ZIP_STORED. Changed in version 2.7: The compression_type