{"id":938894,"date":"2024-12-26T20:21:26","date_gmt":"2024-12-26T12:21:26","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/938894.html"},"modified":"2024-12-26T20:21:28","modified_gmt":"2024-12-26T12:21:28","slug":"python-%e5%a6%82%e4%bd%95%e6%96%87%e4%bb%b6%e5%a4%8d%e5%88%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/938894.html","title":{"rendered":"python \u5982\u4f55\u6587\u4ef6\u590d\u5236"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25074155\/5d4a0ddf-d5dc-4b67-8fd6-ff34ee987be8.webp\" alt=\"python \u5982\u4f55\u6587\u4ef6\u590d\u5236\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u6587\u4ef6\u590d\u5236\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u6a21\u5757<code>shutil<\/code>\u3001<code>os<\/code>\u6a21\u5757\u4ee5\u53ca\u624b\u52a8\u8bfb\u53d6\u548c\u5199\u5165\u6587\u4ef6\u7b49\u65b9\u6cd5\u3002\u63a8\u8350\u4f7f\u7528<code>shutil<\/code>\u6a21\u5757\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u7b80\u5355\u4e14\u9ad8\u6548\u7684\u63a5\u53e3\u6765\u8fdb\u884c\u6587\u4ef6\u590d\u5236\u64cd\u4f5c\u3002<\/strong> <code>shutil.copy()<\/code>\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u51fd\u6570\uff0c\u5b83\u80fd\u590d\u5236\u6587\u4ef6\u7684\u5185\u5bb9\u548c\u6743\u9650\uff0c\u4f46\u4e0d\u5305\u62ec\u5143\u6570\u636e\u3002<code>shutil.copy2()<\/code>\u5219\u53ef\u4ee5\u590d\u5236\u6587\u4ef6\u7684\u5185\u5bb9\u3001\u6743\u9650\u4ee5\u53ca\u5143\u6570\u636e\u3002<code>os<\/code>\u6a21\u5757\u53ef\u4ee5\u7528\u4e8e\u66f4\u4f4e\u7ea7\u7684\u6587\u4ef6\u64cd\u4f5c\uff0c\u4f46\u901a\u5e38\u9700\u8981\u624b\u52a8\u5904\u7406\u6587\u4ef6\u6d41\u3002\u5982\u679c\u9700\u8981\u590d\u5236\u6574\u4e2a\u76ee\u5f55\uff0c<code>shutil.copytree()<\/code>\u662f\u4e00\u4e2a\u5408\u9002\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4e0d\u540c\u7684\u6587\u4ef6\u590d\u5236\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<h2><strong>\u4e00\u3001\u4f7f\u7528SHUTIL\u6a21\u5757\u590d\u5236\u6587\u4ef6<\/strong><\/h2>\n<p><p><code>shutil<\/code>\u6a21\u5757\u662fPython\u6807\u51c6\u5e93\u7684\u4e00\u90e8\u5206\uff0c\u4e13\u95e8\u7528\u4e8e\u9ad8\u9636\u6587\u4ef6\u64cd\u4f5c\uff0c\u5305\u62ec\u6587\u4ef6\u590d\u5236\u3002<\/p>\n<\/p>\n<p><h2>1.1\u3001\u4f7f\u7528shutil.copy()<\/h2>\n<\/p>\n<p><p><code>shutil.copy(src, dst)<\/code>\u662f\u6700\u7b80\u5355\u7684\u6587\u4ef6\u590d\u5236\u65b9\u6cd5\u3002\u5b83\u590d\u5236\u6587\u4ef6\u5185\u5bb9\u548c\u6743\u9650\uff0c\u4f46\u4e0d\u590d\u5236\u5143\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import shutil<\/p>\n<p>def copy_file(src, dst):<\/p>\n<p>    try:<\/p>\n<p>        shutil.copy(src, dst)<\/p>\n<p>        print(f&quot;File {src} copied to {dst} successfully.&quot;)<\/p>\n<p>    except FileNotFoundError:<\/p>\n<p>        print(&quot;The source file does not exist.&quot;)<\/p>\n<p>    except PermissionError:<\/p>\n<p>        print(&quot;Permission denied.&quot;)<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;Error occurred: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u89e3\u91ca<\/strong>\uff1a<code>shutil.copy()<\/code>\u51fd\u6570\u9700\u8981\u4e24\u4e2a\u53c2\u6570\uff1a\u6e90\u6587\u4ef6\u8def\u5f84<code>src<\/code>\u548c\u76ee\u6807\u8def\u5f84<code>dst<\/code>\u3002\u5982\u679c\u76ee\u6807\u8def\u5f84\u662f\u4e00\u4e2a\u76ee\u5f55\uff0c\u5b83\u4f1a\u5c06\u6587\u4ef6\u590d\u5236\u5230\u8be5\u76ee\u5f55\u4e2d\u3002<\/p>\n<\/p>\n<p><h2>1.2\u3001\u4f7f\u7528shutil.copy2()<\/h2>\n<\/p>\n<p><p><code>shutil.copy2(src, dst)<\/code>\u4e0e<code>shutil.copy()<\/code>\u7c7b\u4f3c\uff0c\u4f46\u5b83\u8fd8\u590d\u5236\u6587\u4ef6\u7684\u5143\u6570\u636e\uff0c\u5982\u4fee\u6539\u65f6\u95f4\u548c\u8bbf\u95ee\u6743\u9650\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import shutil<\/p>\n<p>def copy_file_with_metadata(src, dst):<\/p>\n<p>    try:<\/p>\n<p>        shutil.copy2(src, dst)<\/p>\n<p>        print(f&quot;File {src} copied to {dst} with metadata successfully.&quot;)<\/p>\n<p>    except FileNotFoundError:<\/p>\n<p>        print(&quot;The source file does not exist.&quot;)<\/p>\n<p>    except PermissionError:<\/p>\n<p>        print(&quot;Permission denied.&quot;)<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;Error occurred: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u89e3\u91ca<\/strong>\uff1a<code>shutil.copy2()<\/code>\u9002\u7528\u4e8e\u9700\u8981\u4fdd\u7559\u6587\u4ef6\u5c5e\u6027\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h2>1.3\u3001\u4f7f\u7528shutil.copyfile()<\/h2>\n<\/p>\n<p><p><code>shutil.copyfile(src, dst)<\/code>\u4ec5\u590d\u5236\u6587\u4ef6\u5185\u5bb9\uff0c\u4e0d\u590d\u5236\u6743\u9650\u548c\u5143\u6570\u636e\u3002\u76ee\u6807\u5fc5\u987b\u662f\u5b8c\u6574\u6587\u4ef6\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import shutil<\/p>\n<p>def copy_file_strict(src, dst):<\/p>\n<p>    try:<\/p>\n<p>        shutil.copyfile(src, dst)<\/p>\n<p>        print(f&quot;File {src} copied to {dst} successfully.&quot;)<\/p>\n<p>    except FileNotFoundError:<\/p>\n<p>        print(&quot;The source file does not exist.&quot;)<\/p>\n<p>    except PermissionError:<\/p>\n<p>        print(&quot;Permission denied.&quot;)<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;Error occurred: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u89e3\u91ca<\/strong>\uff1a\u9002\u7528\u4e8e\u53ea\u9700\u590d\u5236\u6587\u4ef6\u5185\u5bb9\u7684\u60c5\u51b5\uff0c\u4e14\u76ee\u6807\u8def\u5f84\u5fc5\u987b\u662f\u4e00\u4e2a\u6587\u4ef6\uff0c\u800c\u4e0d\u662f\u76ee\u5f55\u3002<\/p>\n<\/p>\n<h2><strong>\u4e8c\u3001\u4f7f\u7528OS\u6a21\u5757\u8fdb\u884c\u6587\u4ef6\u590d\u5236<\/strong><\/h2>\n<p><p><code>os<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u66f4\u5e95\u5c42\u7684\u6587\u4ef6\u64cd\u4f5c\u529f\u80fd\uff0c\u4f46\u9700\u8981\u624b\u52a8\u5904\u7406\u6587\u4ef6\u6d41\u3002<\/p>\n<\/p>\n<p><h2>2.1\u3001\u624b\u52a8\u8bfb\u53d6\u548c\u5199\u5165\u6587\u4ef6<\/h2>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>os<\/code>\u6a21\u5757\u624b\u52a8\u6253\u5f00\u3001\u8bfb\u53d6\u548c\u5199\u5165\u6587\u4ef6\u6765\u5b9e\u73b0\u590d\u5236\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>def copy_file_manual(src, dst):<\/p>\n<p>    try:<\/p>\n<p>        with open(src, &#39;rb&#39;) as fsrc:<\/p>\n<p>            with open(dst, &#39;wb&#39;) as fdst:<\/p>\n<p>                while True:<\/p>\n<p>                    buf = fsrc.read(1024 * 1024)<\/p>\n<p>                    if not buf:<\/p>\n<p>                        break<\/p>\n<p>                    fdst.write(buf)<\/p>\n<p>        print(f&quot;File {src} copied to {dst} successfully.&quot;)<\/p>\n<p>    except FileNotFoundError:<\/p>\n<p>        print(&quot;The source file does not exist.&quot;)<\/p>\n<p>    except PermissionError:<\/p>\n<p>        print(&quot;Permission denied.&quot;)<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;Error occurred: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u89e3\u91ca<\/strong>\uff1a\u8fd9\u79cd\u65b9\u6cd5\u63d0\u4f9b\u4e86\u5bf9\u590d\u5236\u8fc7\u7a0b\u7684\u5b8c\u5168\u63a7\u5236\uff0c\u53ef\u4ee5\u5904\u7406\u5927\u6587\u4ef6\u548c\u7f51\u7edc\u6d41\u7b49\u590d\u6742\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h2>2.2\u3001\u4f7f\u7528os.system\u8c03\u7528\u64cd\u4f5c\u7cfb\u7edf\u547d\u4ee4<\/h2>\n<\/p>\n<p><p>\u8fd8\u53ef\u4ee5\u901a\u8fc7<code>os.system()<\/code>\u8c03\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684<code>cp<\/code>\u547d\u4ee4\u8fdb\u884c\u590d\u5236\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>def copy_file_os_command(src, dst):<\/p>\n<p>    try:<\/p>\n<p>        command = f&quot;cp {src} {dst}&quot;<\/p>\n<p>        os.system(command)<\/p>\n<p>        print(f&quot;File {src} copied to {dst} using OS command successfully.&quot;)<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;Error occurred: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u89e3\u91ca<\/strong>\uff1a\u8fd9\u79cd\u65b9\u6cd5\u4f9d\u8d56\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u7684\u547d\u4ee4\uff0c\u8de8\u5e73\u53f0\u517c\u5bb9\u6027\u8f83\u5dee\uff0c\u4e0d\u63a8\u8350\u5728\u9700\u8981\u79fb\u690d\u7684\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u3002<\/p>\n<\/p>\n<h2><strong>\u4e09\u3001\u590d\u5236\u6574\u4e2a\u76ee\u5f55<\/strong><\/h2>\n<p><p>\u5728\u8bb8\u591a\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u590d\u5236\u7684\u4e0d\u4ec5\u662f\u5355\u4e2a\u6587\u4ef6\uff0c\u800c\u662f\u6574\u4e2a\u76ee\u5f55\u3002<\/p>\n<\/p>\n<p><h2>3.1\u3001\u4f7f\u7528shutil.copytree()<\/h2>\n<\/p>\n<p><p><code>shutil.copytree(src, dst)<\/code>\u53ef\u4ee5\u9012\u5f52\u5730\u590d\u5236\u6574\u4e2a\u76ee\u5f55\u6811\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import shutil<\/p>\n<p>def copy_directory(src, dst):<\/p>\n<p>    try:<\/p>\n<p>        shutil.copytree(src, dst)<\/p>\n<p>        print(f&quot;Directory {src} copied to {dst} successfully.&quot;)<\/p>\n<p>    except FileExistsError:<\/p>\n<p>        print(&quot;The destination directory already exists.&quot;)<\/p>\n<p>    except FileNotFoundError:<\/p>\n<p>        print(&quot;The source directory does not exist.&quot;)<\/p>\n<p>    except PermissionError:<\/p>\n<p>        print(&quot;Permission denied.&quot;)<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;Error occurred: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u89e3\u91ca<\/strong>\uff1a<code>shutil.copytree()<\/code>\u81ea\u52a8\u5904\u7406\u5b50\u76ee\u5f55\u548c\u6587\u4ef6\uff0c\u975e\u5e38\u9002\u5408\u9700\u8981\u5b8c\u6574\u590d\u5236\u76ee\u5f55\u7ed3\u6784\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h2>3.2\u3001\u590d\u5236\u76ee\u5f55\u4e2d\u7684\u7279\u5b9a\u6587\u4ef6\u7c7b\u578b<\/h2>\n<\/p>\n<p><p>\u53ef\u4ee5\u7ed3\u5408<code>os<\/code>\u548c<code>shutil<\/code>\u6a21\u5757\u590d\u5236\u76ee\u5f55\u4e2d\u67d0\u79cd\u7279\u5b9a\u7c7b\u578b\u7684\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>import shutil<\/p>\n<p>def copy_specific_file_type(src, dst, file_extension):<\/p>\n<p>    try:<\/p>\n<p>        for root, dirs, files in os.walk(src):<\/p>\n<p>            for file in files:<\/p>\n<p>                if file.endswith(file_extension):<\/p>\n<p>                    full_file_path = os.path.join(root, file)<\/p>\n<p>                    shutil.copy(full_file_path, dst)<\/p>\n<p>        print(f&quot;Files with extension {file_extension} from {src} copied to {dst} successfully.&quot;)<\/p>\n<p>    except FileNotFoundError:<\/p>\n<p>        print(&quot;The source directory does not exist.&quot;)<\/p>\n<p>    except PermissionError:<\/p>\n<p>        print(&quot;Permission denied.&quot;)<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;Error occurred: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u89e3\u91ca<\/strong>\uff1a\u8fd9\u79cd\u65b9\u6cd5\u901a\u8fc7\u904d\u5386\u6e90\u76ee\u5f55\uff0c\u627e\u5230\u5339\u914d\u7684\u6587\u4ef6\u7c7b\u578b\u5e76\u590d\u5236\u5230\u76ee\u6807\u76ee\u5f55\u3002<\/p>\n<\/p>\n<h2><strong>\u56db\u3001\u9519\u8bef\u5904\u7406\u548c\u6027\u80fd\u4f18\u5316<\/strong><\/h2>\n<p><p>\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u6587\u4ef6\u590d\u5236\u64cd\u4f5c\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u9519\u8bef\uff0c\u9700\u8981\u8fdb\u884c\u9002\u5f53\u7684\u9519\u8bef\u5904\u7406\u548c\u6027\u80fd\u4f18\u5316\u3002<\/p>\n<\/p>\n<p><h2>4.1\u3001\u9519\u8bef\u5904\u7406<\/h2>\n<\/p>\n<p><p>\u4f7f\u7528<code>try<\/code>\u548c<code>except<\/code>\u5757\u6355\u6349\u548c\u5904\u7406\u5e38\u89c1\u9519\u8bef\uff0c\u5982<code>FileNotFoundError<\/code>\u548c<code>PermissionError<\/code>\u3002<\/p>\n<\/p>\n<p><p><strong>\u89e3\u91ca<\/strong>\uff1a\u786e\u4fdd\u7a0b\u5e8f\u4e0d\u4f1a\u56e0\u672a\u5904\u7406\u7684\u5f02\u5e38\u800c\u5d29\u6e83\uff0c\u5e76\u5411\u7528\u6237\u63d0\u4f9b\u6709\u7528\u7684\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h2>4.2\u3001\u6027\u80fd\u4f18\u5316<\/h2>\n<\/p>\n<p><p>\u5bf9\u4e8e\u5927\u6587\u4ef6\uff0c\u4f7f\u7528\u8f83\u5927\u7684\u7f13\u51b2\u533a\uff08\u4f8b\u59821MB\uff09\u53ef\u4ee5\u63d0\u9ad8\u590d\u5236\u901f\u5ea6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def copy_large_file(src, dst):<\/p>\n<p>    try:<\/p>\n<p>        with open(src, &#39;rb&#39;) as fsrc, open(dst, &#39;wb&#39;) as fdst:<\/p>\n<p>            while True:<\/p>\n<p>                buf = fsrc.read(1024 * 1024)  # 1MB buffer<\/p>\n<p>                if not buf:<\/p>\n<p>                    break<\/p>\n<p>                fdst.write(buf)<\/p>\n<p>        print(f&quot;Large file {src} copied to {dst} successfully.&quot;)<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;Error occurred: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u89e3\u91ca<\/strong>\uff1a\u4f7f\u7528\u8f83\u5927\u7684\u7f13\u51b2\u533a\u80fd\u51cf\u5c11I\/O\u64cd\u4f5c\u7684\u6b21\u6570\uff0c\u4ece\u800c\u63d0\u5347\u590d\u5236\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><h2>4.3\u3001\u591a\u7ebf\u7a0b\u590d\u5236<\/h2>\n<\/p>\n<p><p>\u5bf9\u4e8e\u9700\u8981\u540c\u65f6\u590d\u5236\u591a\u4e2a\u6587\u4ef6\u7684\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u7ebf\u7a0b\u6765\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import threading<\/p>\n<p>def copy_file_thread(src, dst):<\/p>\n<p>    shutil.copy(src, dst)<\/p>\n<p>    print(f&quot;File {src} copied to {dst} in a thread.&quot;)<\/p>\n<p>def copy_files_multithread(file_list, dst):<\/p>\n<p>    threads = []<\/p>\n<p>    for src in file_list:<\/p>\n<p>        thread = threading.Thread(target=copy_file_thread, args=(src, dst))<\/p>\n<p>        threads.append(thread)<\/p>\n<p>        thread.start()<\/p>\n<p>    for thread in threads:<\/p>\n<p>        thread.join()<\/p>\n<p>    print(&quot;All files copied in multiple threads.&quot;)<\/p>\n<h2><strong>Example usage<\/strong><\/h2>\n<p>file_list = [&#39;file1.txt&#39;, &#39;file2.txt&#39;, &#39;file3.txt&#39;]<\/p>\n<p>copy_files_multithread(file_list, &#39;\/path\/to\/destination\/&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u89e3\u91ca<\/strong>\uff1a\u591a\u7ebf\u7a0b\u53ef\u4ee5\u5728I\/O\u64cd\u4f5c\u4e0a\u63d0\u5347\u6027\u80fd\uff0c\u4f46\u9700\u8981\u5c0f\u5fc3\u5904\u7406\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p>\u8fd9\u4e9b\u65b9\u6cd5\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u5f0f\u6765\u5e94\u5bf9\u4e0d\u540c\u7684\u6587\u4ef6\u590d\u5236\u9700\u6c42\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6548\u7387\u548c\u53ef\u9760\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u590d\u5236\u6587\u4ef6\uff1f<\/strong><br \/>\u4f7f\u7528Python\u590d\u5236\u6587\u4ef6\u53ef\u4ee5\u901a\u8fc7\u6807\u51c6\u5e93\u4e2d\u7684<code>shutil<\/code>\u6a21\u5757\u5b9e\u73b0\u3002<code>shutil.copy(src, dst)<\/code>\u51fd\u6570\u53ef\u4ee5\u5c06\u6e90\u6587\u4ef6<code>src<\/code>\u590d\u5236\u5230\u76ee\u6807\u8def\u5f84<code>dst<\/code>\u3002\u5982\u679c\u76ee\u6807\u8def\u5f84\u662f\u4e00\u4e2a\u76ee\u5f55\uff0c\u6e90\u6587\u4ef6\u5c06\u88ab\u590d\u5236\u5230\u8be5\u76ee\u5f55\u4e2d\uff0c\u6587\u4ef6\u540d\u4fdd\u6301\u4e0d\u53d8\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u590d\u5236\u6587\u4ef6\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4e8b\u9879\uff1f<\/strong><br \/>\u5728\u590d\u5236\u6587\u4ef6\u65f6\uff0c\u786e\u4fdd\u6e90\u6587\u4ef6\u8def\u5f84\u6b63\u786e\uff0c\u5e76\u4e14\u76ee\u6807\u8def\u5f84\u6709\u5199\u5165\u6743\u9650\u3002\u5982\u679c\u76ee\u6807\u6587\u4ef6\u5df2\u7ecf\u5b58\u5728\uff0c<code>shutil.copy<\/code>\u5c06\u8986\u76d6\u5b83\u3002\u6b64\u5916\uff0c\u5982\u679c\u9700\u8981\u4fdd\u7559\u6587\u4ef6\u7684\u6743\u9650\u548c\u5143\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>shutil.copy2(src, dst)<\/code>\uff0c\u5b83\u4f1a\u590d\u5236\u6587\u4ef6\u7684\u6240\u6709\u4fe1\u606f\u3002<\/p>\n<p><strong>Python\u662f\u5426\u652f\u6301\u6279\u91cf\u590d\u5236\u6587\u4ef6\uff1f<\/strong><br \/>\u662f\u7684\uff0cPython\u53ef\u4ee5\u901a\u8fc7\u904d\u5386\u6587\u4ef6\u5939\u4e2d\u7684\u6587\u4ef6\u6765\u5b9e\u73b0\u6279\u91cf\u590d\u5236\u3002\u53ef\u4ee5\u4f7f\u7528<code>os<\/code>\u6a21\u5757\u7ed3\u5408<code>shutil<\/code>\u6a21\u5757\uff0c\u904d\u5386\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\uff0c\u5e76\u5c06\u5b83\u4eec\u590d\u5236\u5230\u76ee\u6807\u76ee\u5f55\u3002\u8fd9\u6837\u53ef\u4ee5\u4e00\u6b21\u6027\u5904\u7406\u591a\u4e2a\u6587\u4ef6\uff0c\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u6587\u4ef6\u590d\u5236\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u6a21\u5757shutil\u3001os\u6a21\u5757\u4ee5\u53ca\u624b\u52a8\u8bfb\u53d6\u548c\u5199\u5165\u6587\u4ef6\u7b49 [&hellip;]","protected":false},"author":3,"featured_media":938897,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/938894"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=938894"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/938894\/revisions"}],"predecessor-version":[{"id":938898,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/938894\/revisions\/938898"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/938897"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=938894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=938894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=938894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}