Python Glossary Русский

Python 3.4+Exceptionsexception

shutil.SameFileError

module exceptions

Raised when source and destination are the same file

Syntax

raise shutil.SameFileError

Sameness is decided by device and inode, not by comparing path strings, so a symlink, a hard link or './data.txt' versus its absolute form all count as one file. The check is there to protect your data: without it copyfile would open the destination for writing and truncate the original to zero. A common way to hit it is copy(file, directory) when the file already lives in that directory — the destination expands to directory/name and lands on the source.

Examples

import shutil
try:
    raise shutil.SameFileError
except shutil.SameFileError as e:
    print(type(e).__name__)   # → SameFileError

See also

Open in the full glossarydocs.python.orgReport an inaccuracy