Additionally, os.access()
:
if os.access("myfile", os.R_OK): with open("myfile") as fp: return fp.read()
Being R_OK
, W_OK
, and X_OK
the flags to test for permissions (doc).
Additionally, os.access()
:
if os.access("myfile", os.R_OK): with open("myfile") as fp: return fp.read()
Being R_OK
, W_OK
, and X_OK
the flags to test for permissions (doc).