• 文件、文件夹是否存在
if (not os.path.exists(file)):
    print("file not exists")
  • 是否能访问
os.access(path, mode)

mode:
os.F_OK: 检查文件是否存在
os.R_OK: 检查文件是否可读
os.W_OK: 检查文件是否可以写入
os.X_OK: 检查文件是否可以执行
  • open
try:
    f = open(file_path, "wb")
    f.close()
except FileNotFoundError:
    print "File is not found."
except PersmissionError:
    print "You don't have permission to access this file."