Python_API_ZipFile_write_待填充

ZipFile.write(filename[,arcname[, compress_type]])

Write the file named filename to the archive, giving it the archive namearcname (by default, this will be the same as filename, 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. Callingwrite() on a closed ZipFile will raise aRuntimeError.

Note

There is no official file name encoding for ZIP files. If you have unicode file names, you must convert them to byte strings in your desired encoding before passing them towrite(). WinZip interprets all file 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 separator.

Note

If arcname (orfilename, if arcname is not given) contains a null byte, the name of the file in the archive will be truncated at the null byte.

ZipFile.writestr(zinfo_or_arcname,bytes[, compress_type])

Write the string bytes to the archive; zinfo_or_arcname is either the file name it will be given in the archive, or aZipInfo instance. If it’s an instance, at least the filename, 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. Callingwritestr() on a closed ZipFile will raise aRuntimeError.

If given, compress_type overrides the value given for thecompression 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 thezinfo_or_arcname parameter, the compression method used will be that specified in thecompress_type member of the given ZipInfo instance. By default, theZipInfo constructor sets this member toZIP_STORED.

Changed in version 2.7:The compression_type argument.

The following data attributes are also available:

ZipFile.debug
The level of debug output to use. This may be set from0 (the default, no output) to3 (the most output). Debugging information is written tosys.stdout.
ZipFile.comment
The comment text associated with the ZIP file. If assigning a comment to aZipFile instance created with mode ‘a’ or ‘w’, this should be a string no longer than 65535 bytes. Comments longer than this will be truncated in the written archive when ZipFile.close() is called.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值