Skip to content

Instantly share code, notes, and snippets.

@hackjutsu
Created September 13, 2016 21:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hackjutsu/3d90a786a49698c80c8e62209f3eebe7 to your computer and use it in GitHub Desktop.
Save hackjutsu/3d90a786a49698c80c8e62209f3eebe7 to your computer and use it in GitHub Desktop.
Check whether a file exists using Python
# 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