[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!'
else:
print 'nah'
Kent
At 04:32 PM 8/17/2004 +0200, 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
>
>sPath = 'C:\\file.txt'
>
>if os.access( sPath, F_OK ) == 1:
> print 'yeah!'
>else:
> print 'nah'
>
>
>
>
>Thanks in advance
>Bernard
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list