On this page
  1. shutil.copyfile
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

shutil.copyfile

Prev: shutil.copy2 | Up: shutil | Next: shutil.copyfileobj
Rel: shutil.chown, shutil.copy, shutil.copy2, shutil.copyfileobj
Ref: docs.python.org — shutil.copyfile
Tags: #public #python3 #stdlib #shutil


Import

import shutil
from shutil import copyfile

Signature & Overview

shutil.copyfile(src, dst, *, follow_symlinks=True)

Copy data from src to dst in the most efficient way possible.

Usage

from pathlib import Path
import shutil
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    src = Path(tmp) / "src.txt"
    dst = Path(tmp) / "dst.txt"
    src.write_text("bytes only", encoding="utf-8")
    shutil.copyfile(src, dst)
    assert dst.read_text(encoding="utf-8") == "bytes only"

Gotchas

REPL Inspect

from shutil import copyfile
help(copyfile)

Linked from

Related notes