Getting better traceback info on exec and execfile - introspection?

Ziga Seilnacht ziga.seilnacht at
Sun Jan 15 23:27:50 CET 2006

R. Bernstein wrote:
> which is perhaps is a little more honest since one is not really in a
> file called <string>. However the way the debugger gets this *is*
> still a little hoaky in that it looks for something in the frame's
> f_code.co_filename *called* <string>. And from that it *assumes* this
> is an exec, so it can't really tell the difference between an exec
> command an execfile command, or a file called <string>. But I suppose
> a little more hoakiness *could* be added to look at the outer frame
> and parse the source line for "exec" or "execfile".

You should check the getFrameInfo function in zope.interface package:

> And suppose instead of '<string>' I'd like to give the value or the
> leading prefix of the value instead of the unhelpful word '<string>'?
> How would one do that? Again, one way is to go into the outer frame
> get the source line (if that exists), parse that and interpolate
> argument to exec(file). Is there are better way?

Py library ( has some
similar functionality in the code subpackage.

More information about the Python-list mailing list