Exception.__init__ needed in derived class?

Bjorn Pettersen BPettersen at NAREX.com
Wed Apr 23 15:32:38 EDT 2003


> From: george young [mailto:gry at ll.mit.edu] 
> 
> [python-2.3a1]
> Does class Exception have a constructor __init__ that needs
> to be called?  I couldn't find this in the docs.  I see many
> uses of inheriting from Exception without invoking
> Exception.__init__(self), but nobody ever *said* that this 
> was safe to leave out...
[...]

I can't find it documented anywhere either... In any case, Exception
looks like this:

  class Exception:
     def __init__(self, args):
         self.args = args
     def __str__(self):
         if len(self.args) == 0: return ''
         if len(self.args) == 1: return str(self.args[0])
         return str(self.args)
     def __getitem__(self, k):
         return self.args[k]

(quickly translated, there might be others [I couldn't follow the trail
of populate_methods..] :-)  I don't think I've seen __getitem__
documented either...

-- bjorn





More information about the Python-list mailing list