On this page
genericpath.isfile
Prev: genericpath.isdir | Up: genericpath | Next: genericpath.isjunction
Rel: genericpath.commonprefix, genericpath.exists, genericpath.getatime, genericpath.getctime
Ref: docs.python.org — genericpath.isfile
Tags: #public #python3 #stdlib #genericpath
Import
import genericpath
from genericpath import isfile
Signature & Overview
genericpath.isfile(path)
Test whether a path is a regular file
Usage
import os
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
p = Path(tmp) / "a.txt"
p.write_text("hi")
assert os.path.isfile(p) is True and os.path.isfile(tmp) is False
Gotchas
- Prefer
Path.is_file()oros.path.isfile()over importinggenericpath.
REPL Inspect
from genericpath import isfile
help(isfile)
Linked from
Related notes
- tuts/python3/stdlib_module/genericpath/isdir Linked here; links to this page; shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/isjunction Linked here; links to this page; shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/genericpath/commonprefix Linked here; shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/exists Linked here; shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/getatime Linked here; shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/getctime Linked here; shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/getmtime shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/getsize shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/isdevdrive shared tags: #genericpath, #stdlib