Copyright (C) 2000-2012 |
GNU Info (python2.1-lib.info)ZipFile ObjectsZipFile Objects --------------- `ZipFile(file[, mode[, compression]])' Open a ZIP file, where FILE can be either a path to a file (i.e. a string) or a file-like object. The MODE 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. For MODE is `'a'' and FILE refers to an existing ZIP file, then additional files are added to it. If FILE 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 as `python.exe'. Using cat myzip.zip >> python.exe also works, and at least `WinZip' can read such files. COMPRESSION is the ZIP compression method to use when writing the archive, and should be `ZIP_STORED' or `ZIP_DEFLATED'; unrecognized values will cause `RuntimeError' to be raised. If `ZIP_DEFLATED' is specified but the `zlib' module is not available, `RuntimeError' is also raised. The default is `ZIP_STORED'. `close()' Close the archive file. You must call `close()' before exiting your program or essential records will not be written. `getinfo(name)' Return a `ZipInfo' object with information about the archive member NAME. `infolist()' Return a list containing a `ZipInfo' 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 to `sys.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 return `None'. `write(filename[, arcname[, compress_type]])' Write the file named FILENAME to the archive, giving it the archive name ARCNAME (by default, this will be the same as FILENAME). 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''. `writestr(zinfo, bytes)' Write the string BYTES to the archive; meta-information is given as the `ZipInfo' instance ZINFO. At least the filename, date, and time must be given by ZINFO. 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 from `0' (the default, no output) to `3' (the most output). Debugging information is written to `sys.stdout'. |