使用try--expect跳过代码中的warning,然后正常执行代码

使用try–expect跳过代码中的warning,然后正常执行代码

  • 在Python中,可以使用warnings.simplefilter()函数来捕获警告并将其转换为异常。
  • 可以使用以下代码来捕获警告并跳过它们:
import warnings

warnings.simplefilter("ignore")

然后,可以使用try-except块来捕获异常。例如:

try:
    # your code here
except Exception as e:
    print(e)

你可能感兴趣的:(日常问题,python)