Solution 1: os.path
Check is file
import os.pathos.path.isfile(filename)
Check if file or directory exists
os.path.exists(filename)
Check if directory
os.path.isdir(filename)
Solution 2: pathlib
p = Path(filename)p.is_file()p.is_dir()p.exists()
NOTE: Python 3.4 pathlib or pathlib2 for Python 2.x