Help with super()

Peter Otten __peter__ at web.de
Mon Dec 6 23:25:53 CET 2004


Christopher J. Bottaro wrote:

> Why don't this code work?
> 
> import PRI
> 
> class Poscdnld_PYIO(PRI.BasicBatch):
>    
>    def __init__(self, *argv):
>       super(Poscdnld_PYIO, self).__init__(*argv)
> 
> x = Poscdnld_PYIO()
> 
> I get this exception:
> File "poscdnld_pyio.py", line 52, in __init__
>     super(Poscdnld_PYIO, self).__init__(*argv)
> TypeError: super() argument 1 must be type, not classobj
> 
> What am I doing wrong?  Thanks.

super() does not work with classic classes:

>>> class Classic: pass
...
>>> class A(Classic):
...     def __init__(self):
...             super(A, self).__init__()
...
>>> A()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 3, in __init__
TypeError: super() argument 1 must be type, not classobj

whereas:

>>> class A(object):
...     def __init__(self):
...             super(A, self).__init__()
...
>>> A()
<__main__.A object at 0x402ac02c>

Invoking

def __init__(self, *argv):
    PRI.BasicBatch.__init__(self, *argv)

explicitly instead works as well unless you need cooperative methods which
are only possible with newstyle classes.

Peter






More information about the Python-list mailing list