?? raising.py
字號:
#!/usr/bin/python
# -*- coding: cp936 -*-
#fielname:raising.py
class ShortInputException(Exception):
'''自己定義的輸入字符串太短的異常類
拋出ShortInputException異常'''
def __init__(self,length,atleast):
Exception.__init__(self)
self.length=length
self.atleast=atleast
try:
s=raw_input("請你輸入一個字符串")
if len(s)<3:
raise ShortInputException(len(s),3)
except ShortInputException,x:
print "你輸入的字符串太短,你的輸入是%d,期望得到%d"%(x.length,x.atleast)
else:
print"沒有異常發生"
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -