How do I set permissions (attributes) on a file in a ZIP file using Python's zipfile module?

前端 未结 7 2127
甜味超标
甜味超标 2020-11-30 06:20

When I extract files from a ZIP file created with the Python zipfile module, all the files are not writable, read only etc.

The file is being created and extracted u

7条回答
  •  孤城傲影
    2020-11-30 06:50

    Also look at what Python's zipfile module does:

    def write(self, filename, arcname=None, compress_type=None):
        ...
        st = os.stat(filename)
        ...
        zinfo = ZipInfo(arcname, date_time)
        zinfo.external_attr = (st[0] & 0xFFFF) << 16L      # Unix attributes
        ...
    

    ```

提交回复
热议问题