[Tutor] os.access(), problems with mode variable

Bernard Lebel python at bernardlebel.com
Tue Aug 17 16:32:41 CEST 2004


Hello,

Trying to test the existence of a file, using the access function from the
os module.
In the documentation it is said to use F_OK as the mode for such thing.
However when I run the code below, I get a "NameError: name 'F_OK' is not
defined".

Any suggestion?


import os

sPath = 'C:\\file.txt'

if os.access( sPath, F_OK ) == 1:
    print 'yeah!'
else:
    print 'nah'




Thanks in advance
Bernard



More information about the Tutor mailing list