[Tutor] Test for file existance

Alan Gauld alan.gauld at blueyonder.co.uk
Mon Aug 30 23:54:21 CEST 2004


> 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

That's because F_OK is defined in the os module, 
so you need to use os.F_OK

But why not use the much sipler os.path.exists() 
function instead?

Alan G.



More information about the Tutor mailing list