Python自定义异常没有以正确的语法给出消息

2024-10-01 15:32:44 发布

您现在位置:Python中文网/ 问答频道 /正文

在下面的代码片段中,我得到的响应是-

__main__.CheckSumNotMatched: ('Kirti matches with - ', 'Kirti', ' . They are same.')

class CheckSumNotMatched(Exception):
    """Raised when the remote file's checksum doesn't match with local file checksum"""
    pass

def test(name):
    try:
        if name=="Kirti":
            error_msg = 'Kirti matches with - ', name, '. They are same. '
            raise CheckSumNotMatched(error_msg)
    except CheckSumNotMatched as csnm:
        logger.error(csnm)


if __name__ == "__main__":
    test("Kirti")

我想要的答复是- __main__.CheckSumNotMatched: Kirti matches with - Kirti. They are same.

我不想(和'在回应。 正确的方法应该是什么


Tags: nametestifmainwithmsgerrorare

热门问题