[Tutor] Calling super in __init__

Paul McGuire ptmcg at austin.rr.com
Mon May 19 14:43:02 CEST 2008


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Hi - I wrote a custom exception class as follows:

class CustomError(Exception):
    def __init__(self, msg):
        super(CustomError, self).__init__(self, msg)

But this doesn't work as expected:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Correct use of super would be:

class CustomError(Exception):
    def __init__(self, msg):
        super(CustomError, self).__init__(msg)

(Don't add self as an argument.)

Exception became a new-style class in Python 2.5.

-- Paul



More information about the Tutor mailing list