Python-Erweiterung mit - unter Verwendung von super () Python 3 vs Python 2

Eigentlich wollte ich fragendiese Frage, aber dann habe ich festgestellt, dass schon früher daran gedacht wurde ...

Beim googeln habe ich dieses Beispiel gefundenconfigparser erweitern. Folgendes funktioniert mit Python 3:

<code>$ python3
Python 3.2.3rc2 (default, Mar 21 2012, 06:59:51) 
[GCC 4.6.3] on linux2
>>> from configparser import  SafeConfigParser
>>> class AmritaConfigParser(SafeConfigParser):
...     def __init_(self):
...         super().__init__()
... 
>>> cfg = AmritaConfigParser()
</code>

Aber nicht mit Python 2:

<code>>>> class AmritaConfigParser(SafeConfigParser):
...       def __init__(self):
...           super(SafeConfigParser).init()
... 
>>> cfg = AmritaConfigParser()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in __init__
TypeError: must be type, not classob
</code>

Dann las ich ein wenig über Python New Class vs. Old Class-Stile (z.Hier. Und jetzt wundere ich mich, ich kann tun:

<code>class MyConfigParser(ConfigParser.ConfigParser):
      def Write(self, fp):
          """override the module's original write funcition"""
          ....
      def MyWrite(self, fp):
          """Define new function and inherit all others"""
</code>

Aber sollte ich nicht init anrufen? Ist dies in Python 2 das Äquivalent:

<code> class AmritaConfigParser(ConfigParser.SafeConfigParser):
    #def __init__(self):
    #    super().__init__() # Python3 syntax, or rather, new style class syntax ...
    #
    # is this the equivalent of the above ? 
    def __init__(self):
        ConfigParser.SafeConfigParser.__init__(self)
</code>

Antworten auf die Frage(5)

Ihre Antwort auf die Frage