basic python questions

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Mon Nov 20 16:59:11 EST 2006


Paddy a écrit :
> Bruno Desthuilliers wrote:
> 
>>And this would be still more informative (and not deprecated...):
>>
>>filename = '/tmp/foo'
>>f = open(fliename)
>>
>>Catching an exception just to raise a less informative one is somewhat
>>useless IMHO.
> 
> 
> Except that in the 'artificial' environment of homework, you are marked
> for what you *show* you know, Catching an exception shows that the
> pupil considered that opening a file could throw an exception.

Surely - but then he should also show that he knows what to do with it 
(ie sys.exit with a friendlier error message). Bad exception handling is 
worse than no exception handling (MHO based on experience).

> You would have to comment  that a try except block was considered, give
> an example of correct usage, then why it was not used, to get
> equivalent, (or slightly higher), marks.

This should certainly get a *far* better marks than a broken exception 
handling...

FWIW, the real problem here is with the xref function being responsible 
for file access. It should of course take a filelike object and let the 
caller deal with opening/closing the file - and handling possible 
exceptions in a way that's appropriate.



More information about the Python-list mailing list