简体   繁体   English

我有一个 python 文件,每个块都有多个异常,我需要对相同的 . 有没有办法一次性覆盖所有异常?

[英]I have a python file with multiple exception for each block , I need to utest for the same . Is there any approach to cover all exceptions at one go?

Sample python file for which utest is to be written:要为其编写 utest 的示例 python 文件:

try:

    code

except Exception as e:
    print



try:

    code

except Exception as e:

    print

try:

    code

except Exception as e:

    print

try:

    code

except Exception as e:

    print

try:

    code

except Exception as e:

    print

try:

    code

except Exception as e:

    print
    

try:

    code

except Exception as e:

    print

I think you are looking for this:我想你正在寻找这个:

try:
    foo()
except (SomeException, OtherException, AnotherException) as exp:
    ...

https://docs.python.org/3/tutorial/errors.html#handling-exceptions https://docs.python.org/3/tutorial/errors.html#handling-exceptions

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python异常:为任何异常调用相同的函数 - Python exceptions: call same function for any Exception 我将如何处理多个文件异常? - How would i go about handling multiple file exceptions? 我有 25.csv 文件(每个文件都是一个抄写员)都在相同的结构(X、Y 和 STATUE)中。 我想将它们全部合并到一个 large.txt 文件中 - I have 25 .csv files (each file is a scribe) all in same structure (X, Y and STATUE). I want to combine all of them into one large .txt file 我有一个非常大的 xml 文件(几乎 1 gb)我需要将 xml 文件拆分为 3 个较小的文件。 都具有相同的标题。 我想用 Python 做 - I have a very large xml file (almost 1 gb) I need to split the xml file into 3 smaller files. All with the same headers. I would like to do in Python 我需要从文本文件中将数据作为Python 3中的列表导入,并让程序为每个项目运行一个函数 - I need to import data from a text file as a list in Python 3 and have the program run a function for each item Python:try块可能有多个异常语句吗? - Python: Is it possible to have multiple exceptions statments for a try block? 我需要帮助在 python 中打印此模式,我已经给出了我的方法,但无法弄清楚请支持 - I need help to print this pattern in python, i have given my approach but couldnt figure out pls support 如何使用 pytest 测试 try/except 块并涵盖所有异常 - How to test try/except block with pytest and cover all exceptions 嵌入式 Python 模块中可以有多个输入吗? - Can I have multiple inputs in a Embedded Python Block? 我需要从多个 csv 文件名中捕获日期,并使用 Python 在每个文件中将该日期添加为新列 - I need to capture date from multiple csv filenames and add that date in each file as a new column using Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM