This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mnewman
Recipients georg.brandl, mnewman
Date 2010-02-24.14:12:35
SpamBayes Score 9.0744573e-10
Marked as misclassified No
Message-id <1267020758.71.0.873581563668.issue8011@psf.upfronthosting.co.za>
In-reply-to
Content
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
mike@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
mike@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:
mike@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.
History
Date User Action Args
2010-02-24 14:12:38mnewmansetrecipients: + mnewman, georg.brandl
2010-02-24 14:12:38mnewmansetmessageid: <1267020758.71.0.873581563668.issue8011@psf.upfronthosting.co.za>
2010-02-24 14:12:36mnewmanlinkissue8011 messages
2010-02-24 14:12:36mnewmancreate