Created
August 14, 2017 18:23
-
-
Save takwas/3b7a6edddef783f2abddffda1439f533 to your computer and use it in GitHub Desktop.
Exception message printing demo
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
########### | |
# Python 2: | |
########### | |
try: | |
raise Exception | |
except Exception as e: | |
s,r = getattr(e, 'message') or str(e), getattr(e, 'message') or repr(e) | |
print 's:', s, 'len(s):', len(s) | |
print 'r:', r, 'len(r):', len(r) | |
########### | |
# Python 3: | |
########### | |
try: | |
raise Exception | |
except Exception as e: | |
s,r = getattr(e, 'message', str(e)), getattr(e, 'message', repr(e)) | |
print ('s:', s, 'len(s):', len(s)) | |
print ('r:', r, 'len(r):', len(r)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment