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


Groups > comp.lang.python > #21711 > unrolled thread

Re: Context Manager getting str instead of AttributeError instance

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2012-03-15 14:33 -0600
Last post2012-03-15 14:33 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Context Manager getting str instead of AttributeError instance Ian Kelly <ian.g.kelly@gmail.com> - 2012-03-15 14:33 -0600

#21711 — Re: Context Manager getting str instead of AttributeError instance

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-03-15 14:33 -0600
SubjectRe: Context Manager getting str instead of AttributeError instance
Message-ID<mailman.701.1331843658.3037.python-list@python.org>
On Thu, Mar 15, 2012 at 2:25 PM, Prasad, Ramit
<ramit.prasad@jpmorgan.com> wrote:
>> > ...
>> > (<type 'exceptions.AttributeError'>, "'A' object has no attribute 'x'",
>> <traceback object at 0x1817F648>)
>> > AttributeError: 'A' object has no attribute 'x'
>> >
>> > As you can see, I am getting a string while you are not.
>>
>>Ian Kelly said:
>> Looks like a version difference.  I don't have Python 2.6 handy to
>> test on, but I get a str in Python 2.5 and an AttributeError instance
>> in Python 2.7.
>
> Thanks Ian, that was the key! I guess I will just have to work around it.
> Any suggestions? I am thinking about just creating a blank instance of
> the error class since that the class gets passed successfully.

Well, for what you want to do, I don't think you need an instance at
all -- just use issubclass instead of isinstance:

def __exit__( self, exceptionClass, exception, tracebackObject ):
   if issubclass( exceptionClass, self.exceptionClasses ):
        #do something here

Cheers,
Ian

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web