exec and traceback

ken.py at gameofy.com ken.py at gameofy.com
Mon Jan 22 03:22:16 EST 2018



I'm using exec() to run a (multi-line) string of python code. If an  
exception occurs, I get a traceback containing a stack frame for the  
string. I've labeled the code object with a "file name" so I can  
identify it easily, and when I debug, I find that I can interact with  
the context of that stack frame, which is pretty handy.

What I would like to also be able to do is make the code string  
visible to the debugger so I can look at and step through the code in  
the string as if it were from a python file.

Lest this topic forks into a security discussion, I'll just add that  
for my purposes the data source is trusted. If you really want to talk  
about the security of using exec and eval, fine, but start another  
thread (BTW, I've written a simple secure eval())....

Thanks in advance,
Ken






More information about the Python-list mailing list