Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'except:': 0.07; 'exception.': 0.07; 'pil': 0.07; 'try:': 0.07; 'failed:': 0.09; 'ioerror:': 0.09; 'files.': 0.13; '.txt': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject:exception': 0.16; 'wrote:': 0.17; 'basically': 0.17; 'test.': 0.17; 'file:': 0.22; 'example': 0.23; 'raise': 0.24; 'script': 0.24; 'specifically': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'received:192.168.1.3': 0.29; 'error': 0.30; 'code': 0.31; 'file': 0.32; 'received:84': 0.32; 'to:addr:python-list': 0.33; 'doing': 0.35; 'except': 0.36; 'subject:with': 0.36; 'test': 0.36; 'bad': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'notice': 0.39; 'received:192.168': 0.40; 'identify': 0.61; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'reply-to:addr:python.org': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=YaM/Fntf c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=b2nRVtXOy8EA:10 a=0d4Ps_agHkcA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=hQsut2Grg8wA:10 a=wP_YQVm17UAKt5jkuPEA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Sun, 14 Oct 2012 16:13:59 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Understanding and dealing with an exception References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350227640 news.xs4all.nl 6922 [2001:888:2000:d::a6]:40080 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31252 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?