How to use os.access()??

Peter Hansen peter at
Sat Jul 14 06:52:20 CEST 2001

bvdpoel at wrote:
> I'm trying to use os.access() in my program. But, I'm stuck trying to
> figure out the parms... obviously the first is the filename; but the 2nd
> is supposed to be a constant (?) like F_OK. Unfortunately, it doesn't
> appear that the F_OK, etc are defined anywhere. Either the docs are
> wrong (no way!), or I'm missing a module file (likely), or I'm just
> totally wrong about everything (quite likely!).

You're right! (that you're totally wrong... ;-)

>>> import os
>>> dir(os)
'P_NOWAITO', 'P_OVERLAY', 'P_WAIT', 'R_OK', 'TMP_MAX', 'UserDict', 
'W_OK', 'X_OK', ... ]
>>> os.access('c:/autoexec.bat', os.F_OK)
>>> F_OK
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'F_OK' is not defined
>>> os.F_OK
>>> from os import *
>>> F_OK

You've probably forgotten to use os.F_OK and are using just F_OK.

Unless you want to "from os import *", which is generally bad form,
you need to prepend the name of the module in front of _everything_
you use from that module, whether function name or constant.

Peter Hansen, P.Eng.
peter at

More information about the Python-list mailing list