Tthe simplest, IMHO, is :
try: 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 ...
Pierre
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 34398 MONTPELLIER CEDEX 5, France
tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
