super() woes (n00b)

J. Cliff Dyer jcd at sdf.lonestar.org
Thu Jun 17 13:48:45 EDT 2010


On Thu, 2010-06-17 at 16:36 +0000, Deadly Dirk wrote:
> I cannot get right the super() function:
> Python 3.1.1+ (r311:74480, Nov  2 2009, 14:49:22) 
> [GCC 4.4.1] on linux2
> Type "copyright", "credits" or "license()" for more information.
> ==== No Subprocess ====
> >>> class P:
>     def __init__(__class__,self):
>         print("I am a member of class P")
> 
>         
> >>> class C(P):
>     def __init__(self):
>         super().__init__(self)
>         print("I am a member of class C")
> 
>         
> 
> class P:
>     def __init__(self):
>         print("I am a member of class P")
> 
> class C(P):
>     def __init__(self):
>         super().__init__(self)
>         print("I am a member of class C")
> 
> x=C()
> 
> That is more or less the text from the "Quick Python Book". What am I 
> doing wrong?
> 

super gives you an instantiated version of the super class, which means
that you don't have to explicitly send self to any methods you call on
it.  

So use `super().__init__()` instead.
> -- 
> The missionaries go forth to Christianize the savages - 
> as if the savages weren't dangerous enough already.





More information about the Python-list mailing list