class ShortInputException(Exception):
'''A user-defined exception class.'''
def __init__(self, length, atleast):
Exception.__init__(self)
self.length = length
self.atleast = atleast
try:
s = raw_input('Enter something --> ')
if len(s) < 3:
raise ShortInputException(len(s), 3)
except ShortInputException, x:
print 'ShortInputException: The input was of length %d, \
was expecting at least %d' % (x.length, x.atleast)
I dont understand the syntax of this line: except ShortInputException, x:
what is x here for ?? and why is it acting as an object ???
waht does this line do ? : Exception.__init__(self)
Thanks
super(ShortInputException, self).__init__(self)thanException.__init__(self); but in your code as written, it will work out the same.