basic python questions

P

Paddy

Bruno said:
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.
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.

(That was drilled into me so many times at school).

- Paddy.
 
B

Bruno Desthuilliers

Paddy a écrit :
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top