Re: Understanding and dealing with an exception

Discussion in 'Python' started by MRAB, Oct 14, 2012.

  1. MRAB

    MRAB Guest

    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?
    MRAB, Oct 14, 2012
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Angelico
    Replies:
    0
    Views:
    163
    Chris Angelico
    Oct 14, 2012
  2. Chris Angelico
    Replies:
    0
    Views:
    179
    Chris Angelico
    Oct 14, 2012
  3. Chris Angelico
    Replies:
    0
    Views:
    222
    Chris Angelico
    Oct 14, 2012
  4. Mark Lawrence
    Replies:
    0
    Views:
    141
    Mark Lawrence
    Oct 14, 2012
  5. Terry Reedy
    Replies:
    0
    Views:
    134
    Terry Reedy
    Oct 14, 2012
Loading...

Share This Page