python - Python custom exception not giving message in proper syntax
问题描述
In the following code snippet, I get the response as -
__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")
I want the response as -
__main__.CheckSumNotMatched: Kirti matches with - Kirti. They are same.
I don't want ( and ' in the response. What should be the right way to do that?
解决方案
你可以更换
error_msg = 'Kirti matches with - ', name, '. They are same. '
和
error_msg = 'Kirti matches with - ' + name + '. They are same. '
推荐阅读
- python - 使用 TransactionEncoder 对具有不同元素数量的列表进行单热编码
- python - 构建 Python 脚本以基于方法 POST 自动化错误时间
- spring - Spring 4 对 Caffeine Cache 的支持
- javascript - 如何在视口顶部应用滚动动画+计算适当的百分比?
- encoding - dotNetRDF owl 文件编码为中文
- python - ImportError:无法从“jupyter_client.provisioning”导入名称“KernelProvisionerBase”
- html - 我将样式 css 文件设置为设计,但它不显示为原始页面?
- azure - Terraform Azure 服务主体客户端密码过期
- c# - 为什么这个类层次结构违反 LSP?
- javascript - 根据域白名单设置 cookie 策略