Pythonのexceptブロックでは、エラーメッセージを出力したいのですが、プログラムの実行を停止したくありません。次のようにする必要があることは理解しています。
try:
1/0
except:
print errorMessage
exceptの部分には、Javaのようなものを入れようと考えていますprintStackTrace()
ベストアンサー1
を見てみましょうtraceback.print_exc()
そして残りのtraceback
モジュール。
import traceback
try:
1/0
except:
print '>>> traceback <<<'
traceback.print_exc()
print '>>> end of traceback <<<'
他にもいくつか例がありますtraceback
ドキュメントページの最後のほう。