首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

Python入门到放弃 | 超简单 跟我学(十一)

exceptions_raise.py ): class ShortInputException(Exception): '''用户定义的异常对象''' def __init__(self, length, atleast...__init__(self) self.length = length self.atleast = atleast try: text = input('Enter...ShortInputException: The input was ' + '{0} long, expected at least {1}') .format(ex.length, ex.atleast...它有两个字段, length 是给出输入的长度, atleast 是程序所期望的最小长度。 在 except 子句中,我们注意到错误的类通过 as 把错误或异常对应的对象储存到了命名的变量中。...在特定的 except 子句中,我们用异常对象的 length 和 atleast 字段向用户输出适当的信息。 Try … Finally 假设你要在你的程序中读取一个文件。

37130
领券