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

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


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

Any suggestion?

import os

sPath = 'C:\\file.txt'

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

Thanks in advance

More information about the Tutor mailing list