• <bdo id='B1NH3'></bdo><ul id='B1NH3'></ul>

    <small id='B1NH3'></small><noframes id='B1NH3'>

    1. <tfoot id='B1NH3'></tfoot>
    2. <i id='B1NH3'><tr id='B1NH3'><dt id='B1NH3'><q id='B1NH3'><span id='B1NH3'><b id='B1NH3'><form id='B1NH3'><ins id='B1NH3'></ins><ul id='B1NH3'></ul><sub id='B1NH3'></sub></form><legend id='B1NH3'></legend><bdo id='B1NH3'><pre id='B1NH3'><center id='B1NH3'></center></pre></bdo></b><th id='B1NH3'></th></span></q></dt></tr></i><div id='B1NH3'><tfoot id='B1NH3'></tfoot><dl id='B1NH3'><fieldset id='B1NH3'></fieldset></dl></div>

        <legend id='B1NH3'><style id='B1NH3'><dir id='B1NH3'><q id='B1NH3'></q></dir></style></legend>

        如何使用 Python 的 zipfile 模块对 ZIP 文件中的文件

        时间:2023-09-13
          <legend id='PmzR2'><style id='PmzR2'><dir id='PmzR2'><q id='PmzR2'></q></dir></style></legend>

              • <bdo id='PmzR2'></bdo><ul id='PmzR2'></ul>
                    <tbody id='PmzR2'></tbody>
                  <i id='PmzR2'><tr id='PmzR2'><dt id='PmzR2'><q id='PmzR2'><span id='PmzR2'><b id='PmzR2'><form id='PmzR2'><ins id='PmzR2'></ins><ul id='PmzR2'></ul><sub id='PmzR2'></sub></form><legend id='PmzR2'></legend><bdo id='PmzR2'><pre id='PmzR2'><center id='PmzR2'></center></pre></bdo></b><th id='PmzR2'></th></span></q></dt></tr></i><div id='PmzR2'><tfoot id='PmzR2'></tfoot><dl id='PmzR2'><fieldset id='PmzR2'></fieldset></dl></div>
                • <small id='PmzR2'></small><noframes id='PmzR2'>

                  <tfoot id='PmzR2'></tfoot>
                  本文介绍了如何使用 Python 的 zipfile 模块对 ZIP 文件中的文件设置权限(属性)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  当我从使用 Python 创建的 ZIP 文件中提取文件时 zipfile 模块,所有文件不可写,只读等.

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

                  文件正在 Linux 和 Python 2.5.2 下创建和提取.

                  The file is being created and extracted under Linux and Python 2.5.2.

                  据我所知,我需要为每个文件设置 ZipInfo.external_attr 属性,但这似乎没有记录在我能找到的任何地方,谁能启发我?

                  As best I can tell, I need to set the ZipInfo.external_attr property for each file, but this doesn't seem to be documented anywhere I could find, can anyone enlighten me?

                  推荐答案

                  这似乎可行(感谢 Evan,将其放在这里,以便该行符合上下文):

                  This seems to work (thanks Evan, putting it here so the line is in context):

                  buffer = "path/filename.zip"  # zip filename to write (or file-like object)
                  name = "folder/data.txt"      # name of file inside zip 
                  bytes = "blah blah blah"      # contents of file inside zip
                  
                  zip = zipfile.ZipFile(buffer, "w", zipfile.ZIP_DEFLATED)
                  info = zipfile.ZipInfo(name)
                  info.external_attr = 0777 << 16L # give full access to included file
                  zip.writestr(info, bytes)
                  zip.close()
                  

                  我仍然希望看到记录此内容的内容...我发现的另一个资源是有关 Zip 文件格式的注释:http://www.pkware.com/documents/casestudies/APPNOTE.TXT

                  I'd still like to see something that documents this... An additional resource I found was a note on the Zip file format: http://www.pkware.com/documents/casestudies/APPNOTE.TXT

                  这篇关于如何使用 Python 的 zipfile 模块对 ZIP 文件中的文件设置权限(属性)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Python 中进行自动属性分配的最佳方法是什么, 下一篇:为什么属性名称不能是 Python 关键字?

                  相关文章

                  最新文章

                • <legend id='pWdIs'><style id='pWdIs'><dir id='pWdIs'><q id='pWdIs'></q></dir></style></legend>
                  <tfoot id='pWdIs'></tfoot>
                  <i id='pWdIs'><tr id='pWdIs'><dt id='pWdIs'><q id='pWdIs'><span id='pWdIs'><b id='pWdIs'><form id='pWdIs'><ins id='pWdIs'></ins><ul id='pWdIs'></ul><sub id='pWdIs'></sub></form><legend id='pWdIs'></legend><bdo id='pWdIs'><pre id='pWdIs'><center id='pWdIs'></center></pre></bdo></b><th id='pWdIs'></th></span></q></dt></tr></i><div id='pWdIs'><tfoot id='pWdIs'></tfoot><dl id='pWdIs'><fieldset id='pWdIs'></fieldset></dl></div>
                  • <bdo id='pWdIs'></bdo><ul id='pWdIs'></ul>

                    <small id='pWdIs'></small><noframes id='pWdIs'>