Skip to content

Instantly share code, notes, and snippets.

@takwas
Created August 14, 2017 18:23
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takwas/3b7a6edddef783f2abddffda1439f533 to your computer and use it in GitHub Desktop.
Save takwas/3b7a6edddef783f2abddffda1439f533 to your computer and use it in GitHub Desktop.
Exception message printing demo
###########
# 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