如何在Python中打印异常?

问题描述:

try:
    something here
except:
    print('the whatever error occurred.')

如何在我的中打印错误/异常,除了:块?

对于Python 2.6和更高版本以及Python 3.x:

For Python 2.6 and later and Python 3.x:

except Exception as e: print(e)

对于Python 2.5及更低版本,用途:

For Python 2.5 and earlier, use:

except Exception,e: print str(e)