Catch KeyError in Python

前端 未结 7 1833
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 14:33

If I run the code:

connection = manager.connect(\"I2Cx\")

The program crashes and reports a KeyError because I2Cx doesn\'t exist (it should be

7条回答
  •  孤城傲影
    2021-02-01 14:51

    If you don't want to handle error just NoneType and use get() e.g.:

    manager.connect.get("")
    

提交回复
热议问题