Author: echuck
Date: 2005-03-11 19:51:15 -0700 (Fri, 11 Mar 2005)
New Revision: 2093
Modified:
Webware/trunk/MiscUtils/Funcs.py
Log:
Added excstr() utility func.
Modified: Webware/trunk/MiscUtils/Funcs.py
===================================================================
--- Webware/trunk/MiscUtils/Funcs.py 2005-03-12 02:50:51 UTC (rev 2092)
+++ Webware/trunk/MiscUtils/Funcs.py 2005-03-12 02:51:15 UTC (rev 2093)
@@ -53,6 +53,20 @@
i = i + 1
return string.join(lines, '\n')
+
+def excstr(e):
+ """
+ Returns a string for the exception in the format that Python normally outputs in interactive
+ shells and such:
+ <ExceptionName>: <message>
+ AttributeError: 'object' object has no attribute 'bar'
+ Neither str(e) nor repr(e) do that.
+ """
+ if e is None:
+ return None
+ return '%s: %s' % (e.__class__.__name__, e)
+
+
# Python 2.3 contains mktemp and mkstemp, both of which accept a
# directory argument. Earlier versions of Python only contained
# mktemp which didn't accept a directory argument. So we have to
|