Except ShortInputException,x中カンマ

2976 ワード

 1 class ShortInputException(Exception):
 2     def __init__(self, length, atleast):
 3         Exception.__init__(self)
 4         self.length = length
 5         self.atleast = atleast
 6         
 7 try:
 8     s = raw_input('Enter something --> ')
 9     
10     if len(s) < 3 :
11         raise ShortInputException(len(s), 3)
12 except EOFError:
13     print '
Why did you do an EOF on me?
' 14 except ShortInputException, x: 15 print 'ShortInputException: The input was of length %d, \ 16 was expecting at least %d' % (x.length, x.atleast) 17 else: 18 print 'No exception was raised.'
x  ShortInputException 
python 2.6
2.6 except ShortInputException as x: