all Python 3osfunction
os.path.isfile
os.path — existence and type checks
Check whether a path exists and is a regular file.
Syntax
os.path.isfile(path)
"Regular file" is meant literally: sockets, named pipes and device files exist, yet isfile returns False for them. A link to a file counts as a file. not isfile(p) does not mean "directory" — the path may simply be missing. For reading it is safer to open the file and handle the exception than to check first.
Examples
import os
print(os.path.isfile(os.__file__)) # → True
print(os.path.isfile('/etc/hosts')) # → True
print(os.path.isfile('/tmp')) # → False (это каталог)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy