Developpez python zip


















Note that if an archive only contains. Using the built-in reload function will fail if called on a module loaded from a ZIP archive; it is unlikely that reload would be needed, since this would imply that the ZIP has been altered during runtime.

Create a new zipimporter instance. The archive and prefix attributes, when combined with a slash, equal the original archivepath argument given to the zipimporter constructor. Here is an example that imports a module from a ZIP archive - note that the zipimport module is not explicitly used.

Navigation index modules next previous Python v2. Open a ZIP file, where file can be either a path to a file 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.

If mode is 'a' and file refers to an existing ZIP file, then additional files are added to it. This is meant for adding a ZIP archive to another file, such as python. If mode is a and the file does not exist at all, it is created.

Changed in version 2. Extract a member from the archive as a file-like object ZipExtFile. The mode parameter, if included, must be one of the following: 'r' the default , 'U' , or 'rU'. Choosing 'U' or 'rU' will enable universal newline support in the read-only object.

Calling open on a closed ZipFile will raise a RuntimeError. Under these circumstances, the object returned by open should not be used after any additional operations are performed on the ZipFile object.

If the ZipFile was created by passing in a string the filename as the first argument to the constructor, then open will create a new file object that will be held by the ZipExtFile, allowing it to operate independently of the ZipFile.

The open , read and extract methods can take a filename or a ZipInfo object. You will appreciate this when trying to read a ZIP file that contains members with duplicate names. Extract a member from the archive to the current working directory; member must be its full name or a ZipInfo object.

Its file information is extracted as accurately as possible. Extract all members from the archive to the current working directory. Return the bytes of the file name in the archive.

The archive must be open for read or append. Calling read on a closed ZipFile will raise a RuntimeError. The mode parameter, if included, must be one of the following: 'r' the default , 'U' , or 'rU'. Choosing 'U' or 'rU' will enable universal newline support in the read-only object. Calling open on a closed ZipFile will raise a RuntimeError.

Under these circumstances, the object returned by open should not be used after any additional operations are performed on the ZipFile object. If the ZipFile was created by passing in a string the filename as the first argument to the constructor, then open will create a new file object that will be held by the ZipExtFile, allowing it to operate independently of the ZipFile.

The open , read and extract methods can take a filename or a ZipInfo object. You will appreciate this when trying to read a ZIP file that contains members with duplicate names. Write the file named filename to the archive, giving it the archive name arcname by default, this will be the same as filename , but without a drive letter and with leading path separators removed.

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. 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 to write. Archive names should be relative to the archive root, that is, they should not start with a path separator.

If arcname or filename , if arcname is not given contains a null byte, the name of the file in the archive will be truncated at the null byte. 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. Instances have one method in addition to those of ZipFile objects.

If the pathname is a file, the filename must end with.



0コメント

  • 1000 / 1000