import os.path def isReadableFile(file_path, file_name): full_path = file_path + "/" + file_name try: if not os.path.exists(file_path): print "File path is invalid." return False else ifelif not os.path.isfile(full_path): print "File does not exist." return False else ifelif not os.access(full_path, os.R_OK): print "File cannot be read." return False else: print "File can be read." return True except IOError as ex: print "I/O error({0}): {1}".format(ex.errno, ex.strerror) except Error as ex: print "Error({0}): {1}".format(ex.errno, ex.strerror) return False #------------------------------------------------------ path = "/usr/khaled/documents/puzzles" fileName = "puzzle_1.txt" isReadableFile(path, fileName) Python uses 'elif' not 'else if' https://docs.python.org/2/reference/compound_stmts.html#elif
import os.path def isReadableFile(file_path, file_name): full_path = file_path + "/" + file_name try: if not os.path.exists(file_path): print "File path is invalid." return False else if not os.path.isfile(full_path): print "File does not exist." return False else if not os.access(full_path, os.R_OK): print "File cannot be read." return False else: print "File can be read." return True except IOError as ex: print "I/O error({0}): {1}".format(ex.errno, ex.strerror) except Error as ex: print "Error({0}): {1}".format(ex.errno, ex.strerror) return False #------------------------------------------------------ path = "/usr/khaled/documents/puzzles" fileName = "puzzle_1.txt" isReadableFile(path, fileName) import os.path def isReadableFile(file_path, file_name): full_path = file_path + "/" + file_name try: if not os.path.exists(file_path): print "File path is invalid." return False elif not os.path.isfile(full_path): print "File does not exist." return False elif not os.access(full_path, os.R_OK): print "File cannot be read." return False else: print "File can be read." return True except IOError as ex: print "I/O error({0}): {1}".format(ex.errno, ex.strerror) except Error as ex: print "Error({0}): {1}".format(ex.errno, ex.strerror) return False #------------------------------------------------------ path = "/usr/khaled/documents/puzzles" fileName = "puzzle_1.txt" isReadableFile(path, fileName) import os.path def isReadableFile(file_path, file_name): full_path = file_path + "/" + file_name try: if not os.path.exists(file_path): print "File path is invalid." return falseFalse else if not os.path.isfile(full_path): print "File does not exist." return falseFalse else if not os.access(full_path, os.R_OK): print "File cannot be read." return falseFalse else: print "File can be read." return trueTrue except IOError as ex: print "I/O error({0}): {1}".format(ex.errno, ex.strerror) except Error as ex: print "Error({0}): {1}".format(ex.errno, ex.strerror) return falseFalse #------------------------------------------------------ path = "/usr/khaled/documents/puzzles" fileName = "puzzle_1.txt" isReadableFile(path, fileName) import os.path def isReadableFile(file_path, file_name): full_path = file_path + "/" + file_name try: if not os.path.exists(file_path): print "File path is invalid." return false else if not os.path.isfile(full_path): print "File does not exist." return false else if not os.access(full_path, os.R_OK): print "File cannot be read." return false else: print "File can be read." return true except IOError as ex: print "I/O error({0}): {1}".format(ex.errno, ex.strerror) except Error as ex: print "Error({0}): {1}".format(ex.errno, ex.strerror) return false #------------------------------------------------------ path = "/usr/khaled/documents/puzzles" fileName = "puzzle_1.txt" isReadableFile(path, fileName) import os.path def isReadableFile(file_path, file_name): full_path = file_path + "/" + file_name try: if not os.path.exists(file_path): print "File path is invalid." return False else if not os.path.isfile(full_path): print "File does not exist." return False else if not os.access(full_path, os.R_OK): print "File cannot be read." return False else: print "File can be read." return True except IOError as ex: print "I/O error({0}): {1}".format(ex.errno, ex.strerror) except Error as ex: print "Error({0}): {1}".format(ex.errno, ex.strerror) return False #------------------------------------------------------ path = "/usr/khaled/documents/puzzles" fileName = "puzzle_1.txt" isReadableFile(path, fileName) import os.path def isReadableFile(file_path, file_name): full_path = file_path + "/" + file_name try: if not os.path.exists(file_path): print "File path is invalid." return false else if not os.path.isfile(full_path): print "File does not exist." return false else if not os.access(full_path, os.R_OK): print "File cannot be read." return false else: print "File can be read." return true except IOError as ex: print "I/O error({0}): {1}".format(ex.errno, ex.strerror) except Error as ex: print "Error({0}): {1}".format(ex.errno, ex.strerror) return false #------------------------------------------------------ path = "/usr/khaled/documents/puzzles" fileName = "puzzle_1.txt" isReadableFile(path, fileName) lang-py