super-problem

Franz Glasner f.glasner at feldmann-mg.com
Tue Apr 15 15:15:44 EDT 2003


super() works only for new style classes.

Derive your class B from object and super() works:

  class B(object):
     ...

Franz.


On Tue, 15 Apr 2003, Max Khesin wrote:

> I was playing with super() and here is my session - the suggested usage of
> super appears to produce an error. What am I missing? thanks -
> max.
>
>
> PythonWin 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32.
> >>> print super.__doc__
> super(type) -> unbound super object
> super(type, obj) -> bound super object; requires isinstance(obj, type)
> super(type, type2) -> bound super object; requires issubclass(type2, type)
> Typical use to call a cooperative superclass method:
> class C(B):
>     def meth(self, arg):
>         super(C, self).meth(arg)
> >>> class B:
> ...  def meth(self, arg):
> ...   print ('B::meth, arg = %s'%arg)
> ...
> >>> class C(B):
> ...  def meth(self, arg):
> ...   super(C, self).meth(arg)
> ...
> >>> c = C()
> >>> c.meth('Ho')
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
>   File "<interactive input>", line 3, in meth
> TypeError: super() argument 1 must be type, not class
>
> --
> ========================================
> Max Khesin, software developer -
> max at cNvOiSsPiAoMntech.com
> [check out our image compression software at www.cvisiontech.com, JBIG2-PDF
> compression @
> www.cvisiontech.com/cvistapdf.html]
>
>
>
>




More information about the Python-list mailing list