[Tutor] [HELP]how to test properties of a file
Shidai Liu
shidai.liu at gmail.com
Sun Apr 3 21:44:16 CEST 2005
On Apr 3, 2005 6:42 PM, Pierre Barbier de Reuille
<pierre.barbier at cirad.fr> wrote:
> 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
>
I thought of this first. But I wasn't sure if it's the simplest.
Thanks for your help!
More information about the Tutor
mailing list