[Tutor] This is driving my crazy! My file hasn't been corrupted

David bouncingcats at gmail.com
Mon Sep 1 08:39:11 CEST 2014


On 1 September 2014 02:31, Richard Dillon <dillonrw at comcast.net> wrote:
>
>     except IOError:
>         print('An error occured trying to read the file.')
>
>     except ValueError:
>         print('Non-numeric data found in the file.')
>
>     except:
>         print('An error occured.')

Your other respondents have already said this, but I am going to emphasise it.

The above lines are bad. They do not help you, they only hinder you by
replacing useful information with dumb print statements that tell you
nothing useful. So delete them all!

'except' blocks should only be used when you know why the error
occurred, and they should contain useful extra code to either to
recover from the error or to work around it.

Those dumb print statements are not useful extra code. So delete them.


More information about the Tutor mailing list