Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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; 'socket': 0.04; 'instance': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:error': 0.10; 'ioerror': 0.16; 'python2.5': 0.16; 'python2.6': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'socket.error': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'import': 0.28; 'print': 0.29; 'from:addr:web.de': 0.30; 'chris': 0.32; 'to:addr:python-list': 0.33; 'test': 0.34; 'header:X-Complaints-To:1': 0.35; 'received:org': 0.38; 'subject:: ': 0.39; 'relatively': 0.39; 'header:Mime-Version:1': 0.39; 'subject:with': 0.39; 'to:addr:python.org': 0.39; 'more': 0.60; 'here': 0.65; 'subject:... ': 0.84; 'subject:types': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: try... except with unknown error types Date: Sat, 10 Sep 2011 12:17:23 +0200 Organization: None References: <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084ac98.dip.t-dialin.net X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315649845 news.xs4all.nl 2468 [2001:888:2000:d::a6]:50555 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:13060 Chris Torek wrote: > >>> import socket > >>> isinstance(socket.error, IOError) > False Here you test if the socket.error *class* is an instance of IOError; this would print True if IOError were socket.error's metaclass. However: >>> isinstance(socket.error(), IOError) True or more directly: >>> issubclass(socket.error, IOError) True >>> issubclass(socket.error, EnvironmentError) True This is a relatively recent change: $ python2.5 -c'from socket import error; print issubclass(error, IOError), issubclass(error, EnvironmentError)' False False $ python2.6 -c'from socket import error; print issubclass(error, IOError), issubclass(error, EnvironmentError)' True True