bug/poor tracebacks while importing code

Robin Becker robin at jessikat.fsnet.co.uk
Wed Oct 2 19:11:07 CEST 2002

In article <mailman.1033573985.1981.python-list at python.org>, Mark
McEahern <marklists at mceahern.com> writes
>[Robin Becker]
>> Is there some reason why we have poor code inspection during imports.
>Is it just me or does your attitude stink?
>Anyway, try this instead:
>  traceback.print_stack()
call me stupid if you wish, but it was a genuine query. And thanks
print_stack does better at locating things when -O is off.

I was trying to use sys._getframe to locate the importing instructions,
but always saw f.f_lasti as zero. It seems there's magic in there

I assumed, perhaps naively, that print_exc would do what it normally
does and give a traceback to the top. It seems that for C python at
least these things depend on whether -O is on and for simple straight
line code the last instruction pointer isn't updated at all regularly.

I suppose somewhere in the bowels of the documentation there will be
caveats on using such low level features and maybe my attitude sucks in
assuming that simple things do what they are said to do.

Looking in the ceval it seems that f_lasti isn't regularly updated
except at particular instructions. Perhaps the reference manual should
indicate that.
Robin Becker

More information about the Python-list mailing list