Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

Use os.path.isfile() with os.access():

import os
import os.path
PATH = './file.txt'
if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
 print("File exists and is readable")
else:
 print("Either the file is missing or not readable")

Use os.path.isfile() with os.access():

import os
import os.path
PATH = './file.txt'
if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
 print("File exists and is readable")
else:
 print("Either the file is missing or not readable")

Use os.path.isfile() with os.access():

import os
PATH = './file.txt'
if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
 print("File exists and is readable")
else:
 print("Either the file is missing or not readable")
Python 2 to Python 3 and fixed formatting of code
Source Link

Use os.path.isfile() with os.access():

import os
import os.path
PATH='PATH = './file.txt'
if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
 print("File exists and is readable")
else:
 print("Either the file is missing or not readable")

Use os.path.isfile() with os.access():

import os
import os.path
PATH='./file.txt'
if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
 print"File exists and is readable"
else:
 print"Either the file is missing or not readable"

Use os.path.isfile() with os.access():

import os
import os.path
PATH = './file.txt'
if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
 print("File exists and is readable")
else:
 print("Either the file is missing or not readable")

Use os.path.isfile() with os.access():

import os
import os.path
PATH='./file.txt'
if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
 print "File exists and is readable"
else:
 print "Either the file is missing or is not readable"

Use os.path.isfile() with os.access():

import os
import os.path
PATH='./file.txt'
if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
 print "File exists and is readable"
else:
 print "Either file is missing or is not readable"

Use os.path.isfile() with os.access():

import os
import os.path
PATH='./file.txt'
if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
 print "File exists and is readable"
else:
 print "Either the file is missing or not readable"
improved importing // added links
Source Link
Honest Abe
  • 8.8k
  • 5
  • 53
  • 66
Loading
suggested edit
Source Link
Yugal Jindle
  • 46k
  • 43
  • 136
  • 201
Loading
Source Link
Yugal Jindle
  • 46k
  • 43
  • 136
  • 201
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /