python版本导致的错误

上一篇 / 下一篇  2014-08-26 14:22:52

class ShortInputException(Exception):
    '''A user-defined exception class.'''
    def __init__(self, length, atleast):
        Exception.__init__(self)
        self.length = length
        self.atleast = atleast
try:
    s = input('Enter someting-->')
    if len(s)<3:
        raise ShortInputException(len(s), 3)
except EOFError:
    print('\nWhy did you do an EOF on me?')
except ShortInputException as x: #python3 中把except ShortInputException, x: 改为了 ShortInputException as x

    print('ShortInputException:The input was of length %d,\
    was expecting at least %d' %(x.length,x.atleast))
else:
    print('No exception was raised.')

TAG:

 

评分:0

我来说两句

Open Toolbar