⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 raising.py

📁 《简明 Python 教程》为 "A Byte of Python" 的唯一指定简体中文译本
💻 PY
字号:
#!/usr/bin/env python# Filename: raising.pyclass ShortInputException(Exception):	'''A user-defined exception class.'''	def __init__(self,length,atleast):		Exception.__init__(self)		self.length=length		self.atleast=atleasttry:	s=raw_input('Enter something --> ')	if len(s)<3:		raise ShortInputException(len(s),3)	# Other work can continue as usual hereexcept EOFError:	print '\nWhy did you do an EOF on me?'except ShortInputException,x:	print 'ShortInputException: The input was of length %d, \was expecting at least %d' %(x.length,x.atleast)else:	print 'No exception was raised.'

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -