Catch KeyError in Python

前端 未结 7 1837
没有蜡笔的小新
没有蜡笔的小新 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:46

    I dont think python has a catch :)

    try:
        connection = manager.connect("I2Cx")
    except Exception, e:
        print e
    

提交回复
热议问题