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

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

          <bdo id='gn5g4'></bdo><ul id='gn5g4'></ul>

        当 cp 没有时,为什么 shutil.copy() 会引发权限异常?

        Why would shutil.copy() raise a permission exception when cp doesn#39;t?(当 cp 没有时,为什么 shutil.copy() 会引发权限异常?)
        • <i id='4rPud'><tr id='4rPud'><dt id='4rPud'><q id='4rPud'><span id='4rPud'><b id='4rPud'><form id='4rPud'><ins id='4rPud'></ins><ul id='4rPud'></ul><sub id='4rPud'></sub></form><legend id='4rPud'></legend><bdo id='4rPud'><pre id='4rPud'><center id='4rPud'></center></pre></bdo></b><th id='4rPud'></th></span></q></dt></tr></i><div id='4rPud'><tfoot id='4rPud'></tfoot><dl id='4rPud'><fieldset id='4rPud'></fieldset></dl></div>
          <legend id='4rPud'><style id='4rPud'><dir id='4rPud'><q id='4rPud'></q></dir></style></legend>
          1. <small id='4rPud'></small><noframes id='4rPud'>

              <tbody id='4rPud'></tbody>

            <tfoot id='4rPud'></tfoot>
            • <bdo id='4rPud'></bdo><ul id='4rPud'></ul>

                • 本文介绍了当 cp 没有时,为什么 shutil.copy() 会引发权限异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  shutil.copy() 引发权限错误:

                  shutil.copy() is raising a permissions error:

                  Traceback (most recent call last):
                    File "copy-test.py", line 3, in <module>
                      shutil.copy('src/images/ajax-loader-000000-e3e3e3.gif', 'bin/styles/blacktie/images')
                    File "/usr/lib/python2.7/shutil.py", line 118, in copy
                      copymode(src, dst)
                    File "/usr/lib/python2.7/shutil.py", line 91, in copymode
                      os.chmod(dst, mode)
                  OSError: [Errno 1] Operation not permitted: 'bin/styles/blacktie/images/ajax-loader-000000-e3e3e3.gif'
                  

                  复制测试.py:

                  import shutil
                  
                  shutil.copy('src/images/ajax-loader-000000-e3e3e3.gif', 'bin/styles/blacktie/images')
                  

                  我正在从命令行运行 copy-test.py:

                  I am running copy-test.py from the command line:

                  python copy-test.py
                  

                  但是从命令行对同一文件运行 cp 到同一目的地不会导致错误.为什么?

                  But running cp from the command line on the same file to the same destination doesn't cause an error. Why?

                  推荐答案

                  失败的操作是chmod,而不是副本本身:

                  The operation that is failing is chmod, not the copy itself:

                    File "/usr/lib/python2.7/shutil.py", line 91, in copymode
                      os.chmod(dst, mode)
                  OSError: [Errno 1] Operation not permitted: 'bin/styles/blacktie/images/ajax-loader-000000-e3e3e3.gif'
                  

                  这表明该文件已经存在并且由另一个用户拥有.

                  This indicates that the file already exists and is owned by another user.

                  shutil.copy 已指定复制权限位.如果您只想复制文件内容,请使用 shutil.copyfile(src, dst)shutil.copyfile(src, os.path.join(dst, os.path.basename(src))) 如果 dst 是一个目录.

                  shutil.copy is specified to copy permission bits. If you only want the file contents to be copied, use shutil.copyfile(src, dst), or shutil.copyfile(src, os.path.join(dst, os.path.basename(src))) if dst is a directory.

                  一个与 dst 一起工作的函数,无论是文件还是目录,并且不复制权限位:

                  A function that works with dst either a file or a directory and does not copy permission bits:

                  def copy(src, dst):
                      if os.path.isdir(dst):
                          dst = os.path.join(dst, os.path.basename(src))
                      shutil.copyfile(src, dst)
                  

                  这篇关于当 cp 没有时,为什么 shutil.copy() 会引发权限异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)

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

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