In message <[EMAIL PROTECTED]>, Carl
Banks wrote:

> Consider this: is there any other code in your program that has to do
> something different based on whether you successfully opened this file
> or not?  If so, how will you notify it whether the call has succeeded
> or not?  Very often, the caller itself needs to know.  You could, say,
> set a flag to indicate it's failed, but why do that when you could
> simply let the caller detect and handle the error itself?

I am generally wary of exceptions, and like to contain them as much as
possible. So my answer to your point is something like

    try :
        f = open(TheFile, "r")
    except IOError, (ErrNo, Msg) :
        if ErrNo != errno.ENOENT :
            raise
        #end if
        f = None
    #end try

(Note how I check for the specific error code I want to handle.) Then later
on I can determine if the file was successfully opened by

    if f != None :
        ... further processing on f ...
    #end if

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to