Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:7.15 zipfileUp:7.15 zipfileNext:7.15.2 PyZipFile Objects

 
7.15.1 ZipFile Objects

classZipFile(file[, mode[, compression]])
Open a ZIP file, wherefile can be either a path to a file (a string) or a file-like object. Themode parameter should be'r' to read an existing file,'w' to truncate and write a new file, or'a' to append to an existing file. Formode is'a' andfile refers to an existing ZIP file, then additional files are added to it. Iffile does not refer to a ZIP file, then a new ZIP archive is appended to the file. This is meant for adding a ZIP archive to another file, such aspython.exe. Using

cat myzip.zip >> python.exe

also works, and at leastWinZip can read such files.compression is the ZIP compression method to use when writing the archive, and should beZIP_STORED orZIP_DEFLATED; unrecognized values will causeRuntimeError to be raised. IfZIP_DEFLATED is specified but thezlib module is not available,RuntimeError is also raised. The default isZIP_STORED.

close()
Close the archive file. You must callclose() before exiting your program or essential records will not be written.

getinfo(name)
Return aZipInfo object with information about the archive membername.

infolist()
Return a list containing aZipInfo object for each member of the archive. The objects are in the same order as their entries in the actual ZIP file on disk if an existing archive was opened.

namelist()
Return a list of archive members by name.

printdir()
Print a table of contents for the archive tosys.stdout.

read(name)
Return the bytes of the file in the archive. The archive must be open for read or append.

testzip()
Read all the files in the archive and check their CRC's. Return the name of the first bad file, or else returnNone.

write(filename[, arcname[, compress_type]])
Write the file namedfilename to the archive, giving it the archive namearcname (by default, this will be the same asfilename). If given,compress_type overrides the value given for thecompression parameter to the constructor for the new entry. The archive must be open with mode'w' or'a'.

writestr(zinfo, bytes)
Write the stringbytes to the archive; meta-information is given as theZipInfo instancezinfo. At least the filename, date, and time must be given byzinfo. The archive must be opened with mode'w' or'a'.

The following data attribute is also available:

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.


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:7.15 zipfileUp:7.15 zipfileNext:7.15.2 PyZipFile Objects
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp