Convert exception error to string

前端 未结 2 659
终归单人心
终归单人心 2021-02-01 14:14

I want to work with the error message from an exception but can\'t seem to convert it to a string. I\'ve read the os library man page but something is not clicking for me.

2条回答
  •  离开以前
    2021-02-01 14:57

    From the docs for print()

    All non-keyword arguments are converted to strings like str() does and written to the stream

    So in the first case, your error is converted to a string by the print built-in, whereas no such conversion takes place when you just try and concatenate your error to a string. So, to replicate the behavior of passing the message and the error as separate arguments, you must convert your error to a string with str().

提交回复
热议问题