super

Question related to super() with __init__()

天涯浪子 提交于 2020-01-03 17:03:31
问题 Given 3 classes below, class A(object): def __init__(self): print('A') def test(self): print('1') class B(A): def __init__(self): super(B,self) ## if .__init__() is not given here print('B') class C(B, A): def __init__(self): super(C, self).__init__() print('C') If I run D = C() , it will return B C If I run print(C.__mro__) , it will gives (<class '__main__.C'>, <class '__main__.B'>, <class '__main__.A'>, <class 'object'>) . I think that means class A will be executed as it is inside the mro

Explicit passing of Self when calling super class's __init__ in python

最后都变了- 提交于 2020-01-02 10:07:43
问题 This question is in relation to posts at What does 'super' do in Python? , How do I initialize the base (super) class? , and Python: How do I make a subclass from a superclass? which describes two ways to initialize a SuperClass from within a SubClass as class SuperClass: def __init__(self): return def superMethod(self): return ## One version of Initiation class SubClass(SuperClass): def __init__(self): SuperClass.__init__(self) def subMethod(self): return or class SuperClass: def __init__

Explicit passing of Self when calling super class's __init__ in python

孤人 提交于 2020-01-02 10:07:35
问题 This question is in relation to posts at What does 'super' do in Python? , How do I initialize the base (super) class? , and Python: How do I make a subclass from a superclass? which describes two ways to initialize a SuperClass from within a SubClass as class SuperClass: def __init__(self): return def superMethod(self): return ## One version of Initiation class SubClass(SuperClass): def __init__(self): SuperClass.__init__(self) def subMethod(self): return or class SuperClass: def __init__

Scala overloaded constructors and super

爷,独闯天下 提交于 2020-01-02 05:43:09
问题 I can't understand how to develop Scala code similar to the following on Java: public abstract class A { protected A() { ... } protected A(int a) { ... } } public abstract class B { protected B() { super(); } protected B(int a) { super(a); } } public class C extends B { public C() { super(3); } } while it's clear how to develop C class, I can't get how to receive B. Help, please. P.S. I'm trying to create my own BaseWebPage derived from wicket WebPage which is a common practice for Java 回答1:

python3 - behaviour of super() on multi-inheritance

流过昼夜 提交于 2020-01-02 01:22:30
问题 I know that super() and multi-inheritance have already been discussed here. But I did not find a solution, regarding my specific problem in python3. Let's assume we have: #! /usr/bin/env python3 class A(object): def __init__(self): super().__init__() def foo(self): print("The") class B(object): def __init__(self): super().__init__() def foo(self): print("world") class C(B): def __init__(self): super().__init__() def foo(self): super().foo() print("is") class D(A,C): def __init__(self): super(

Why 'T.super.toString()' and 'super::toString' use a synthetic accessor method?

让人想犯罪 __ 提交于 2020-01-02 01:04:44
问题 Consider the following set of expressions: class T {{ /*1*/ super.toString(); // direct /*2*/ T.super.toString(); // synthetic Supplier<?> s; /*3*/ s = super::toString; // synthetic /*4*/ s = T.super::toString; // synthetic }} Which gives the following result: class T { T(); 0 aload_0 [this] 1 invokespecial java.lang.Object() [8] 4 aload_0 [this] 5 invokespecial java.lang.Object.toString() : java.lang.String [10] 8 pop // ^-- direct 9 aload_0 [this] 10 invokestatic T.access$0(T) : java.lang

Objective C: Difference between self and super

∥☆過路亽.° 提交于 2020-01-01 07:35:52
问题 I am new to Objective C.I am trying aout some example programs.I could not understand how the self and super methods work in objective C. In the pgm below CashTransaction.m [super trackSpending:amount] is called and in CreditCardTransaction.m [self trackSpending:amount] is called.I could not find difference between the self and super.super is for invoking the base class overriden method.and self is for invoking the child class overridden method.This is what my understanding is.please correct

How to make super() work by manually filling the __class__ cell?

倾然丶 夕夏残阳落幕 提交于 2019-12-31 21:35:08
问题 In Python 3 one can use super() instead of super(MyClass, self) , but this only works in methods that were defined inside the class. As described in Michele Simionato's article the following example does not work: def __init__(self): print('calling __init__') super().__init__() class C(object): __init__ = __init__ if __name__ == '__main__': c = C() It fails because super() looks for a __class__ cell, which is not defined in this case. Is it possible to set this cell manually after the

python: super()-like proxy object that starts the MRO search at a specified class

我只是一个虾纸丫 提交于 2019-12-30 23:29:53
问题 According to the docs, super(cls, obj) returns a proxy object that delegates method calls to a parent or sibling class of type cls I understand why super() offers this functionality, but I need something slightly different: I need to create a proxy object that delegates methods calls (and attribute lookups) to class cls itself; and as in super , if cls doesn't implement the method/attribute, my proxy should continue looking in the MRO order (of the new not the original class). Is there any

I can't get super() to work in python 2.7

北城余情 提交于 2019-12-30 15:43:34
问题 With a simple pair of classes, I cannot get super working: class A(object): q = 'foo' class B(A): q = 'bar' def __init__(self): self.a = super(A, self).q a = B() errors like so: --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-210-802575054d17> in <module>() 5 def __init__(self): 6 self.a = super(A, self).q ----> 7 a = B() <ipython-input-210-802575054d17> in __init__(self) 4 q = 'bar' 5 def __init__