Detect file existance before open?
Scott Barron
kain at twilight.
Mon Oct 18 13:51:23 EDT 1999
I've been using os.path.isfile (file) to do something similar. Works well
for me.
-Scott
In article <002701bf196e$81144730$3acbd9c2 at peridot.optichrome.com>,
Adrian Eyre wrote:
>> I would like to check for the existance of a file before I attempt an open
>> and maybe throw an exception. I don't see a way to do this. I would like
>> to tell the user that the file he specified doesn't exist. Is there a way
>> to do this or do I need to catch the exception and deal with it that way?
>
>What's wrong with:
>
>try:
> f=open("afile", "r")
>except IOError, val:
> print "Could not read file: " + val[1]
>
>--------------------------------------------
>Adrian Eyre <mailto:a.eyre at optichrome.com>
>Optichrome Computer Solutions Ltd
>Maybury Road, Woking, Surrey, GU21 5HX, UK
>Tel: +44 1483 740 233 Fax: +44 1483 760 644
>http://www.optichrome.com
>--------------------------------------------
>
>
>
More information about the Python-list
mailing list