logo
  • 教程列表
  • SO官方文檔
  • 檔案和資料夾 IO
    • 檔案模式
    • 逐行讀取檔案
    • 迭代檔案(遞迴)
    • 獲取檔案的完整內容
    • 寫入檔案
    • 檢查檔案或路徑是否存在
    • 隨機檔案訪問使用 mmap
    • 將一個檔案的內容複製到另一個檔案
    • 複製目錄樹
    • 在一系列行之間讀取檔案
    • 替換檔案中的文字
    • 檢查檔案是否為空
  1. StackOverflow 文件
  2. Python Language 教程
  3. 檔案和資料夾 IO
  4. 將一個檔案的內容複製到另一個檔案

將一個檔案的內容複製到另一個檔案

Created: November-22, 2018

with open(input_file, 'r') as in_file, open(output_file, 'w') as out_file:
    for line in in_file:
        out_file.write(line)
  • 使用 shutil 模組:
import shutil
shutil.copyfile(src, dst)
  • 複製目錄樹
  • 隨機檔案訪問使用 mmap

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明