[Tutor] Test for file existance

Michael Janssen Janssen at rz.uni-frankfurt.de
Mon Aug 30 19:31:55 CEST 2004

On Mon, 30 Aug 2004, Klas Marteleur wrote:

> I wanna test for file existance using os.access
> I have tried the following but none seem to work
> os.access("/home/klas/epa.txt", F_OK)
> os.access("/home/klas/epa.txt", f_ok)
> os.access("/home/klas/epa.txt", "F_OK")
> os.access("/home/klas/epa.txt", "f_ok")
> but i get the following error:
> Traceback (most recent call last):
>   File "<pyshell#156>", line 1, in ?
>     kalle = os.access("/home/klas/epa.txt",F_OK)
> NameError: name 'R_OK' is not defined

these are variables defined in the os module. You have to say os.F_OK and
so on. Once the same issue took me some time to figure it out, too.

Actually these variables stand for some integers. The whole matter is that
variable names are easier to memorize and the integers (are unlikly to
but) might change. Same as host-names and IP addresses.


More information about the Tutor mailing list