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

Wolfram Kraus kraus at hagen-partner.de
Tue Aug 17 16:42:45 CEST 2004


Heyho!

Bernard Lebel wrote:
> 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
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!'
> else:
>     print 'nah'
> 
> Thanks in advance
> Bernard
> 
HTH,
Wolfram



More information about the Tutor mailing list