bug/poor tracebacks while importing code

Fernando Pérez fperez528 at yahoo.com
Wed Oct 2 14:05:13 EDT 2002


Robin Becker wrote:

> Is there some reason why we have poor code inspection during imports.
> b.py isn't mentioned in the traceback obtained in c.py in the following
> noddy example and this is limiting my ability to do nasty import tricks.
> This is with stock win32 2.2.1.
> 

The problem is --I think-- rather that by explicitly doing the printing of the 
traceback yourself, you are limiting the scope of the information returned. 

Consider the following changes (I left your b.py unaltered):
[~/test]> cat c.py
"""
CCCCCCCC
"""
a=4
b=5
c=6
d=7
def xxx():
    import traceback, sys
    try:
        raise ValueError
    except:
        print 'ValueError was caught. Re-raising...'
        raise
        #traceback.print_exc()   # COMMENTED OUT FROM ORIGINAL
xxx()
[~/test]> python b.py
ValueError was caught. Re-raising...
Traceback (most recent call last):
  File "b.py", line 5, in ?
    import c
  File "c.py", line 16, in ?
    xxx()
  File "c.py", line 11, in xxx
    raise ValueError
ValueError


In this case you do get information about b, the importer.

hth,

f



More information about the Python-list mailing list