On this page
  1. shutil.SameFileError
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

shutil.SameFileError

Prev: shutil.rmtree | Up: shutil | Next: shutil.SpecialFileError
Rel: shutil.chown, shutil.copy, shutil.copy2, shutil.copyfile
Ref: docs.python.org โ€” shutil.SameFileError
Tags: #public #python3 #stdlib #shutil


Import

import shutil
from shutil import SameFileError

Signature & Overview

shutil.SameFileError(...)

Raised when source and destination are the same file.

Methods & Attributes

Usage

from pathlib import Path
import shutil
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    p = Path(tmp) / "a.txt"
    p.write_text("hi", encoding="utf-8")
    try:
        shutil.copyfile(p, p)
    except shutil.SameFileError:
        assert p.read_text(encoding="utf-8") == "hi"

Gotchas

REPL Inspect

from shutil import SameFileError
help(SameFileError)

Linked from

Related notes