[Tutor] Re: os.access(), problems with mode variable
kraus at hagen-partner.de
Tue Aug 17 16:42:45 CEST 2004
Bernard Lebel wrote:
> 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
Either add the following line:
from os import F_OK
> sPath = 'C:\\file.txt'
> if os.access( sPath, F_OK ) == 1:
Or change this if statement to:
if os.access( sPath, os.F_OK ) == 1:
> print 'yeah!'
> print 'nah'
> Thanks in advance
More information about the Tutor