On Tue, 3 Aug 2010 10:52:27 am Richard D. Moores wrote:
> On Mon, Aug 2, 2010 at 16:57, Steven D'Aprano <[email protected]> 
wrote:
> >  # File *probably* doesn't exist. Consider better error checking.
>
> Steve, before I dig into your detailed reply, please tell me what you
> meant by " # File *probably* doesn't exist. Consider better error
> checking.".

open(pathname) will fail with an IOError for many reasons. It could be 
that the file simply doesn't exist, so it can't be opened. It could be 
that you don't have read permission, or that the disk is corrupt and 
even though you have permission to open the file, attempting to do so 
fails.

For a simple script, it's acceptable to assume that the likely reason 
for IOError is that the file isn't there, and therefore creating it 
will solve the problem. But for a more solid program, you should 
inspect the exception to determine the error code, and then take 
appropriate action.



-- 
Steven D'Aprano
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to