Created
September 13, 2016 21:45
-
-
Save hackjutsu/3d90a786a49698c80c8e62209f3eebe7 to your computer and use it in GitHub Desktop.
Check whether a file exists using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2.x | |
import os.path | |
os.path.isfile(fname) | |
# Python 3.4 | |
from pathlib import Path | |
my_file = Path("/path/to/file") | |
if my_file.is_file(): | |
# file exists |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment