Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'context': 0.04; 'args': 0.05; 'completeness': 0.05; 'instance,': 0.05; 'attribute': 0.07; 'exception,': 0.07; 'python': 0.08; 'subclasses': 0.09; 'exception': 0.12; 'win32': 0.12; 'def': 0.13; 'to:name:python- list@python.org': 0.15; "'a'": 0.16; '*args):': 0.16; '712': 0.16; 'a()': 0.16; 'a.x': 0.16; 'currencies': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'securities,': 0.16; 'self,': 0.16; 'subject:instance': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'seems': 0.20; '(most': 0.21; 'header:In-Reply-To:1': 0.22; 'dec': 0.22; 'string': 0.24; 'traceback': 0.24; 'classes': 0.26; 'not.': 0.28; 'received:169': 0.28; 'received:169.254': 0.28; 'mine': 0.28; 'bit': 0.28; 'see,': 0.29; 'class': 0.29; 'print': 0.29; 'behaves': 0.30; 'received:155': 0.30; 'received:159': 0.30; 'use?': 0.30; 'accuracy': 0.32; 'instead.': 0.32; 'there': 0.33; 'object': 0.33; 'file': 0.34; 'normally': 0.34; 'last):': 0.34; 'subject:getting': 0.34; 'to:addr:python-list': 0.35; 'phone:': 0.35; '...': 0.35; 'something': 0.35; 'but': 0.37; 'charset:us- ascii': 0.37; 'skip:_ 10': 0.38; 'think': 0.38; 'listed': 0.38; 'getting': 0.38; 'to:addr:python.org': 0.40; 'subject': 0.61; 'offers': 0.62; 'here': 0.64; 'account': 0.66; 'taking': 0.66; 'information,': 0.69; 'legal': 0.72; 'url:email': 0.72; 'bank': 0.75; 'sale': 0.75; 'investment': 0.77; 'purchase': 0.78; 'received:169.254.8': 0.84; 'so:': 0.84 X-DKIM: OpenDKIM Filter v2.1.3 sf3.jpmchase.com q2FJB5Qo008870 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=jpmorgan.com; s=smtpout; t=1331838665; bh=68f7GAKNkpylKOuZp1cuuTv9j6LwwwcdwmwGU8Xhirw=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=NnxpKb0cn6ZnZRheW9I34SRQ2kRSwb8fuqUP4uW6YGJZFZV5gVNcXJkAundQY/w2g 07m6FW8Zgqv3KMhHZngNuQXwcafNDq89CwqQ2fesnogn8YES9Rcy/4RxgZ51GCAbp9 IDSq0g+dmmkSfOai4SaFczl5H64IEhwdTGbF2KO4= From: "Prasad, Ramit" To: "python-list@python.org" Subject: RE: Context Manager getting str instead of AttributeError instance Thread-Topic: Context Manager getting str instead of AttributeError instance Thread-Index: Ac0C0ee2HWpMrUyoSZqdW3mY/u0AugADC2TOAAA7KnA= Date: Thu, 15 Mar 2012 19:10:59 +0000 References: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.79.38] Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-DLP-FWD: Yes Content-Type: text/plain; charset="us-ascii" 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1331838674 news.xs4all.nl 6968 [2001:888:2000:d::a6]:53467 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21705 > Prasad, Ramit wrote:=0D=0A> =0D=0A> > So I have a context manager used to= catch errors=0D=0A> >=0D=0A> > def __exit__( self, exceptionClass, excepti= on, tracebackObject ):=0D=0A> > if isinstance( exception, self=2Eexcept= ionClasses ):=0D=0A> > #do something here=0D=0A> >=0D=0A> > Normal= ly exception would be the exception instance, but for=0D=0A> > AttributeErr= or it seems to be a string instead=2E=0D=0A> =0D=0A> I don't think so:=0D= =0A> =0D=0A> >>> class A(object):=0D=0A> =2E=2E=2E def __enter__(self):= return self=0D=0A> =2E=2E=2E def __exit__(self, *args): print args=0D= =0A> =2E=2E=2E=0D=0A> >>> with A() as a:=0D=0A> =2E=2E=2E a=2Ex=0D=0A> = =2E=2E=2E=0D=0A> (, AttributeError("'A'= object has no=0D=0A> attribute 'x'",), )=0D=0A> Traceback (most recent call last):=0D=0A> File "", line = 2, in =0D=0A> AttributeError: 'A' object has no attribute 'x'=0D=0A= > =0D=0A> > 1) Why is AttributeError different than the other built-ins=0D= =0A> > in this respect?=0D=0A> > 2) Are there other standard errors like th= is (I know=0D=0A> > that SystemExit is different as well)?=0D=0A> > 3) Taki= ng into account that I want to include subclasses of=0D=0A> > classes liste= d in self=2EexceptionClasses, Is there a better check I can=0D=0A> > use?= =0D=0A=0D=0ANot sure why mine behaves differently:=0D=0APython 2=2E6=2E6 (r= 266:84292, Dec 17 2010, 12:36:53) [MSC v=2E1500 32 bit (Intel)] on win32=0D= =0A>>> =0D=0A>>> class A(object):=0D=0A=2E=2E=2E def __enter__(self): r= eturn self=0D=0A=2E=2E=2E def __exit__(self, *args): print args=0D=0A= =2E=2E=2E =0D=0A>>> with A() as a:=0D=0A=2E=2E=2E a=2Ex=0D=0A=2E=2E= =2E =0D=0A(, "'A' object has no att= ribute 'x'", )=0D=0AAttributeError: 'A' obj= ect has no attribute 'x'=0D=0A=0D=0AAs you can see, I am getting a string w= hile you are not=2E =0D=0A=0D=0ARamit=0D=0A=0D=0A=0D=0ARamit Prasad | JPMor= gan Chase Investment Bank | Currencies Technology=0D=0A712 Main Street | Ho= uston, TX 77002=0D=0Awork phone: 713 - 216 - 5423=0D=0A=0D=0A--=0D=0A=0D=0A= This email is confidential and subject to important disclaimers and=0D=0Aco= nditions including on offers for the purchase or sale of=0D=0Asecurities, a= ccuracy and completeness of information, viruses,=0D=0Aconfidentiality, leg= al privilege, and legal entity disclaimers,=0D=0Aavailable at http://www=2E= jpmorgan=2Ecom/pages/disclosures/email=2E