且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Python中引用异常类?

更新时间:2023-12-01 21:40:22

您需要正确引用该异常.

You need to reference the exception correctly.

直接将异常导入模块中,或使用完整的参考文献:

Either import the exception directly into your module, or use the full reference:

import gpxpy.gpx

try:
    # ...
except gpxpy.gpx.GPSException:
    # ...

from gpxpy.gpx import GPSException

try:
    # ...
except GPSException:
    # ...