Last active
May 23, 2016 17:07
-
-
Save Highstaker/1ed6dd8f95cd8ed515f42681c1c8cd6f to your computer and use it in GitHub Desktop.
A function that prints the full traceback
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
#!/usr/bin/python3 -u | |
# -*- coding: utf-8 -*- | |
import sys, traceback | |
def full_traceback(): | |
""" | |
Returns a full traceback to an exception | |
:return: | |
""" | |
exc_type, exc_value, exc_traceback = sys.exc_info() | |
a = traceback.format_exception(exc_type, exc_value, exc_traceback) | |
a = "".join(a) | |
return a | |
if __name__ == '__main__': | |
# A quick test | |
def a(): | |
raise KeyError | |
def b(): | |
return a() | |
try: | |
b() | |
except KeyError: | |
print(full_traceback()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment