En Sat, 07 Mar 2009 21:18:22 -0200, BigHand <hewei...@gmail.com> escribió:
On 3月7日, 下午11时21分, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:
En Sat, 07 Mar 2009 11:46:08 -0200, BigHand <hewei...@gmail.com> escribió:

> 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]"

Put your code in a true module stored in a file, so the source lines can  
be retrieved.

    I don't understand you.could you give me more details?


C:\TEMP>type tbtest.py
import sys
import traceback

def a(): b()

def b(): raise ValueError

print("\none\n")
try: a()
except:
  exc_typ, exc_val, exc_tb = sys.exc_info()
  traceback.print_tb(exc_tb)

print("\ntwo\n")
try: a()
except:
  exc_typ, exc_val, exc_tb = sys.exc_info()
traceback.print_tb(exc_tb)

print("\nthree\n")
a()

C:\TEMP>python30 tbtest.py

one

  File "tbtest.py", line 9, in <module>
    try: a()
  File "tbtest.py", line 4, in a
    def a(): b()
  File "tbtest.py", line 6, in b
    def b(): raise ValueError

two

  File "tbtest.py", line 15, in <module>
    try: a()
  File "tbtest.py", line 4, in a
    def a(): b()
  File "tbtest.py", line 6, in b
    def b(): raise ValueError

three

Traceback (most recent call last):
  File "tbtest.py", line 21, in <module>
    a()
  File "tbtest.py", line 4, in a
    def a(): b()
  File "tbtest.py", line 6, in b
    def b(): raise ValueError
ValueError

C:\TEMP>


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to