dis.dis question
Ron Adam
rrr at ronadam.com
Sun Oct 9 08:10:46 EDT 2005
Ron Adam wrote:
>
> Can anyone show me an example of of using dis() with a traceback?
>
> Examples of using disassemble_string() and distb() separately if
> possible would be nice also.
[cliped]
> But I still need to rewrite disassemble_string() and need to test it
> with tracebacks.
>
> Cheers,
> Ron
It seems I've found a bug in dis.py, or maybe a expected non feature.
When running dis from a program it fails to find the last traceback
because sys.last_traceback doesn't get set. (a bug in sys?) It works
ok from the shell, but not from the program.
Changing it to to get sys.exc_info()[2], fix's it in a program, but then
it doesn't work in the shell. So I replaced it with the following which
works in both.
try:
if hasattr(sys,'last_traceback'):
tb = sys.last_traceback
else:
tb = sys.exc_info()[2]
except AttributeError:
raise RuntimeError, "no last traceback to disassemble"
I'm still looking for info on how to use disassemble_string().
Cheers,
Ron
More information about the Python-list
mailing list