Skip to content

Instantly share code, notes, and snippets.

@yusukei
Created September 24, 2011 03:49
Show Gist options
  • Save yusukei/1238934 to your computer and use it in GitHub Desktop.
Save yusukei/1238934 to your computer and use it in GitHub Desktop.
traceback test
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()
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