Skip to content

Instantly share code, notes, and snippets.

@vishvendra01
Created November 3, 2014 13:29
Show Gist options
  • Save vishvendra01/fe9899eaa9bd01a504f1 to your computer and use it in GitHub Desktop.
Save vishvendra01/fe9899eaa9bd01a504f1 to your computer and use it in GitHub Desktop.
Check whether a given file exists or not
# check whether given file exist or not and readable too
import os
# first approach
# I think it is best practice to use this approach
def validate_file(file_name):
if os.path.isfile(file_name) and os.access(file_name, os.R_OK):
return True
else:
return False
# second approach
def validate_file(file_name):
if os.path.exists(file_name):
return True
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment