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

Kent Johnson kent_johnson at skillsoft.com
Tue Aug 17 18:09:27 CEST 2004

FWIW you can also use os.path.exists() for this. It's a bit more readable 
if nothing else:
import os

sPath = 'C:\\file.txt'

if os.path.exists( sPath ):
     print 'yeah!'
     print 'nah'


At 04:32 PM 8/17/2004 +0200, 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
>sPath = 'C:\\file.txt'
>if os.access( sPath, F_OK ) == 1:
>     print 'yeah!'
>     print 'nah'
>Thanks in advance
>Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list