Showing the method's class in expection's traceback

Agustin Villena agustin.villena at gmail.com
Mon May 19 09:54:05 EDT 2008


On May 18, 4:31 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> Agustin Villena schrieb:
>
>
>
> > Hi!
>
> > is there anyway to show the class of amethodin an exception's
> > traceback?
>
> > For example, the next code
>
> > class Some(object):
> >     def foo(self,x):
> >         raise Exception(x)
>
> > obj = Some()
> > obj.foo("some arg")
>
> > produces the next traceback
>
> > Traceback (most recent call last):
> >   File "<string>", line 231, in run_nodebug
> >   File "G:\dev\exceptions\sample.py", line 7, in <module>
> >     obj.foo("some arg")
> >   File "G:\dev\exceptions\sample.py", line 3, in foo
> >     raise Exception(x)
> > Exception: some arg
>
> > I want to improve the line
> > File "G:\dev\exceptions\sample.py", line 3, in foo
>
> > to
> > File "G:\dev\exceptions\sample.py", line 3, in Some.foo
>
> > Is this improvement feasible
>
> It should be. You can get a dictionary of the locals of an exception
> stack frame, of which you could extract the self-parameter's class.
>
> Diez

Hi!

I digged on sys.exc_info() object and the traceback module and I
could't figure how I can get the locals() of the exception stackframe

Any advice?

Thanks
  Agustin



More information about the Python-list mailing list