[Python] Check whether a path exists

Created on November 30, 2026

Use os.path.exists to check whether a path exists. It returns True for an existing file or directory and False for a missing path.

import os

print(os.path.exists('/tmp/dummy.txt'))

If /tmp/dummy.txt exists, the output is as follows.

True
Python