instancemethod

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Sat Jan 27 00:42:11 EST 2007


On Sat, 27 Jan 2007 01:03:50 -0300, Gabriel Genellina wrote:

> "Steven D'Aprano" <steve at REMOVE.THIS.cybersource.com.au> escribió en el 
> mensaje 
> news:pan.2007.01.27.00.07.59.387012 at REMOVE.THIS.cybersource.com.au...
> 
>> On Fri, 26 Jan 2007 17:25:37 +0100, Bruno Desthuilliers wrote:
>>>>    def __del__(self):
>>>>        try:
>>>>            self.close()
>>>>        finally:
>>>>            pass
>>>>        except:
>>>>            pass
>>>
>>> The finally clause is useless here.
>>
>> In principle, closing a file could raise an exception. I've never seen it
>> happen, but it could. From the Linux man pages: [...]
>> I assume that the same will apply in Python.
> 
> Note that he said that the *finally* clause were useless (and I'd say so, 
> too), not the *except* clause.

Doh!

Yes, he's right. Worse, the code as show can't possibly work: the finally
clause must come AFTER the except clause.

>>> try:
...     pass
... finally:
...     pass
... except:
  File "<stdin>", line 5
    except:
         ^
SyntaxError: invalid syntax



-- 
Steven.




More information about the Python-list mailing list