Printing out actual error message for ValueError

后端 未结 2 1576
慢半拍i
慢半拍i 2021-02-06 21:06

How can I actually print out the ValueError\'s message after I catch it?

If I type except ValueError, err: into my code instead of except ValueError a

2条回答
  •  终归单人心
    2021-02-06 21:29

    Python 3 requires casting the exception to string before printing:

    try:
        ...
    except ValueError as error:
        print(str(error))
    

提交回复
热议问题