[Tutor] [HELP]how to test properties of a file

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Sun Apr 3 19:42:23 CEST 2005

Tthe simplest, IMHO, is :

   f = file(filename, "w")
except IOError:
   print "The file is not writable"

Of course, not that this method empty the file if it is writable ! The 
best is to just put your IO code in such a try block ... That way, 
you're sure the file has the right mode.

If you don't want to open the file to detect its mode, then you need to 
use the os and stat modules together ...


Shidai Liu a écrit :
> Dear all,
> Here is a simple question. But I can't find a simple answer.
> How to test if a file is readable, executalbe or writable, especially, writable?

Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68

More information about the Tutor mailing list