Showing the method's class in expection's traceback

Agustin Villena agustin.villena at gmail.com
Sun May 18 16:16:04 EDT 2008


Hi!

is there anyway to show the class of a method in 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



More information about the Python-list mailing list