Created
November 3, 2014 13:29
-
-
Save vishvendra01/fe9899eaa9bd01a504f1 to your computer and use it in GitHub Desktop.
Check whether a given file exists or not
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
# 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