Python Glossary Русский

all Python 3osfunction

os.path.sameopenfile

os.path — metadata (stat)

Check whether two file descriptors refer to the same file.

Syntax

os.path.sameopenfile(fp1, fp2)

It works on descriptor numbers, not paths, so it sees the open objects themselves even if the file was renamed or deleted since. It helps to learn that two descriptors obtained through different paths lead to one file, so writing through one shows up in the other.

Examples

import os
fd = os.open(os.__file__, os.O_RDONLY)
print(os.path.sameopenfile(fd, fd))   # → True
os.close(fd)

See also

Open in the full glossarydocs.python.orgReport an inaccuracy