Created
September 24, 2011 03:49
-
-
Save yusukei/1238934 to your computer and use it in GitHub Desktop.
traceback test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pprint import pprint | |
from cStringIO import StringIO | |
stdout = StringIO() | |
def test(): | |
try: | |
a | |
except: | |
import sys, traceback | |
tb = sys.exc_info()[2] | |
pprint(traceback.extract_tb(tb), stream=stdout) | |
print stdout.getvalue() | |
test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
_ = {} | |
code = '' | |
args = '' | |
argv = {} | |
funcname = 'self' | |
try: | |
print code | |
with open('code.py', 'r') as fp: | |
buf = [] | |
head = True | |
code = 'def '+funcname+'('+args+'):\n' | |
for line in fp.readlines(): | |
code += ' ' + line | |
exec code in _, _ | |
ret = _[funcname](**argv) | |
except: | |
from pprint import pprint | |
import traceback | |
mesg = traceback.format_exc() | |
print mesg | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment