Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31252

Re: Understanding and dealing with an exception

Date 2012-10-14 16:13 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: Understanding and dealing with an exception
References <CALyJZZXtxD5HZCZ6C21-uPgxQUhvWw7xaUZsmPw-whTvhjGBsA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2177.1350227640.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 2012-10-14 05:23, Vincent Davis wrote:
> I am working on a script to find bad image files. I am using PIL
> and specifically image.verify() I have a set of known to be bad image
> files to test. I also what to be able to test any file for example a
> .txt and deal with the exception.
> Currently my code is basically
>
> try:
>      im = Image.open(ifile)
>      try:
>          print(im.verify())
>      except:
>          print('Pil image.verify() failed: ' + afile)
> except IOError:
>      print('PIL cannot identify image file: ' + afile)
> except:
>      print(ifile)
>      print("Unexpected error doing PIL.Image.open():", sys.exc_info()[0])
>      raise
>
[snip]
I notice that you have both "ifile" and "afile". Is that correct?

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Understanding and dealing with an exception MRAB <python@mrabarnett.plus.com> - 2012-10-14 16:13 +0100

csiph-web