can't print the exception cause/context in Python3.0?

BigHand heweiwei at gmail.com
Sat Mar 7 14:46:08 CET 2009


Here is copy from my IDLE of python 3.0

>>> import sys
>>> import traceback
>>> def a():
	b()


>>> def b():
	return tuple()[0]

>>> try:
	a()
except:
	exc_typ, exc_val, exc_tb = sys.exc_info()


>>> traceback.print_tb(exc_tb)
  File "<pyshell#14>", line 2, in <module>
  File "<pyshell#6>", line 2, in a
  File "<pyshell#9>", line 2, in b

but this doesn't output the cause/context like 2.6: or on the sample
of:
http://docs.python.org/3.0/library/traceback.html?highlight=format_exception#traceback.format_exception

I want the exception printted like this:
  File "<pyshell#14>", line 2, in <module>  "a()"
  File "<pyshell#6>", line 2, in a        "b()"
  File "<pyshell#9>", line 2, in b       "return tuple()[0]"


how should I do?



More information about the Python-list mailing list