Equivalent of Super Keyword in C#

C# equivalent of your code is class Imagedata : PDFStreamEngine { // C# uses “base” keyword whenever Java uses “super” // so instead of super(…) in Java we should call its C# equivalent (base): public Imagedata() : base(ResourceLoader.loadProperties(“org/apache/pdfbox/resources/PDFTextStripper.properties”, true)) { } // Java methods are virtual by default, when C# methods aren’t. // So we … Read more

How does Python’s “super” do the right thing?

Change your code to this and I think it’ll explain things (presumably super is looking at where, say, B is in the __mro__?): class A(object): def __init__(self): print “A init” print self.__class__.__mro__ class B(A): def __init__(self): print “B init” print self.__class__.__mro__ super(B, self).__init__() class C(A): def __init__(self): print “C init” print self.__class__.__mro__ super(C, self).__init__() class … Read more

Python super method and calling alternatives

Consider the following situation: class A(object): def __init__(self): print(‘Running A.__init__’) super(A,self).__init__() class B(A): def __init__(self): print(‘Running B.__init__’) # super(B,self).__init__() A.__init__(self) class C(A): def __init__(self): print(‘Running C.__init__’) super(C,self).__init__() class D(B,C): def __init__(self): print(‘Running D.__init__’) super(D,self).__init__() foo=D() So the classes form a so-called inheritance diamond: A / \ B C \ / D Running the code yields … Read more

How to call super method from grandchild class?

Well, this is one way of doing it: class Grandparent(object): def my_method(self): print “Grandparent” class Parent(Grandparent): def my_method(self): print “Parent” class Child(Parent): def my_method(self): print “Hello Grandparent” Grandparent.my_method(self) Maybe not what you want, but it’s the best python has unless I’m mistaken. What you’re asking sounds anti-pythonic and you’d have to explain why you’re doing … Read more

super() and @staticmethod interaction

The short answer to Am I calling super(type) incorrectly here or is there something I’m missing? is: yes, you’re calling it incorrectly… AND (indeed, because) there is something you’re missing. But don’t feel bad; this is an extremely difficult subject. The documentation notes that If the second argument is omitted, the super object returned is … Read more

When do I use super()?

Calling exactly super() is always redundant. It’s explicitly doing what would be implicitly done otherwise. That’s because if you omit a call to the super constructor, the no-argument super constructor will be invoked automatically anyway. Not to say that it’s bad style; some people like being explicit. However, where it becomes useful is when the … Read more