New submission from Michael Newman <michael.b.new...@gmail.com>: In the second example given in "27.8.1. Traceback Examples" at: http://docs.python.org/3.1/library/traceback.html http://docs.python.org/py3k/library/traceback.html which has the lumberjack:
The last line won't work in Python 3.1 and 3.2: print("*** tb_lineno:", traceback.tb_lineno(exceptionTraceback)) because "tb_lineno" is no longer an attribute in the "traceback" module. # Python 2.6 works fine (because Python2 retains the "tb_lineno" attribute in the "traceback" module): # Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 *** print_tb: File "print_traceback_and_exception.py", line 18, in <module> lumberjack() ... *** format_tb: [' File "print_traceback_and_exception.py", line 18, in <module>\n lumberjack()\n', ' File "print_traceback_and_exception.py", line 12, in lumberjack\n bright_side_of_death()\n', ' File "print_traceback_and_exception.py", line 15, in bright_side_of_death\n return tuple()[0]\n'] ('*** tb_lineno:', 18) # Broken example using Python 3.1: # Python 3.1.1 (r311:74480, Feb 7 2010, 16:32:28) [GCC 4.4.1] on linux2 m...@ebx2009:/media/Cruzer/notes/Programming/python3/lib/traceback$ python3.1 print_traceback_and_exception.py *** print_tb: File "print_traceback_and_exception.py", line 18, in <module> lumberjack() ... During handling of the above exception, another exception occurred: Traceback (most recent call last): File "print_traceback_and_exception.py", line 38, in <module> print("*** tb_lineno:", traceback.tb_lineno(exceptionTraceback)) AttributeError: 'module' object has no attribute 'tb_lineno' # Broken example using Python 3.2: # Python 3.2a0 (py3k:78294, Feb 21 2010, 16:37:29) [GCC 4.4.1] on linux2 m...@ebx2009:/media/Cruzer/notes/Programming/python3/lib/traceback$ python3.2 print_traceback_and_exception.py *** print_tb: File "print_traceback_and_exception.py", line 18, in <module> lumberjack() ... During handling of the above exception, another exception occurred: Traceback (most recent call last): File "print_traceback_and_exception.py", line 38, in <module> print("*** tb_lineno:", traceback.tb_lineno(exceptionTraceback)) AttributeError: 'module' object has no attribute 'tb_lineno' This can be corrected by changing the last line of the example from: print("*** tb_lineno:", traceback.tb_lineno(exceptionTraceback)) to: print("*** tb_lineno:", exceptionTraceback.tb_lineno) # Using my "rev1" example: # Python 3.1 now sees the brighter side of life: m...@ebx2009:/media/Cruzer/notes/Programming/python3/lib/traceback$ python3.1 print_traceback_and_exception_rev1.py *** print_tb: File "print_traceback_and_exception_rev1.py", line 19, in <module> lumberjack() ... *** format_tb: [' File "print_traceback_and_exception_rev1.py", line 19, in <module>\n lumberjack()\n', ' File "print_traceback_and_exception_rev1.py", line 13, in lumberjack\n bright_side_of_death()\n', ' File "print_traceback_and_exception_rev1.py", line 16, in bright_side_of_death\n return tuple()[0]\n'] *** tb_lineno: 19 For reference: "print_traceback_and_exception_rev1.py" = example corrected with Python3. The original line has been commented out in case you want to turn it back on and see the error yourself. ---------- assignee: georg.brandl components: Documentation files: print_traceback_and_exception_rev1.py messages: 100033 nosy: georg.brandl, mnewman severity: normal status: open title: traceback tb_lineno example needs correction for Python3 versions: Python 3.1, Python 3.2 Added file: http://bugs.python.org/file16357/print_traceback_and_exception_rev1.py _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue8011> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com