super

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

泪湿孤枕 提交于 2019-12-30 15:42:44
问题 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__

Can I use Python 3 super() in Python 2.5.6?

拈花ヽ惹草 提交于 2019-12-30 07:56:44
问题 Can I use clean Python 3 super() syntax in Python 2.5.6? Maybe with some kind of __future__ import? 回答1: You cannot use a bare super() call that contains no type/class. Nor can you implement a replacement for it that will work. Python 3.x contains special support to enable bare super() calls (it places a __class__ cell variable in all functions defined within a class - see PEP 3135 Update As of Python 2.6+, bare super() calls can be used via the future Python package. See posita's answer for

Python3's super and comprehensions -> TypeError?

不问归期 提交于 2019-12-30 03:10:31
问题 Using python3's super in a comprehension seems to always result in TypeError: super(type, obj): obj must be an instance or subtype of type (but using python 2's super does work as expected) class A(object): def __repr__(self): return "hi!" class B(A): def __repr__(self): return "".join(super().__repr__() for i in range(2)) repr(B()) #output: <repr(<__main__.B at 0x7f70cf36fcc0>) failed: TypeError: super(type, obj): obj must be an instance or subtype of type> class C(A): def __repr__(self): s

Calling parent class __init__ with multiple inheritance, what's the right way?

旧时模样 提交于 2019-12-27 10:22:03
问题 Say I have a multiple inheritance scenario: class A(object): # code for A here class B(object): # code for B here class C(A, B): def __init__(self): # What's the right code to write here to ensure # A.__init__ and B.__init__ get called? There's two typical approaches to writing C 's __init__ : (old-style) ParentClass.__init__(self) (newer-style) super(DerivedClass, self).__init__() However, in either case, if the parent classes ( A and B ) don't follow the same convention, then the code will

Is calling a superinterface's default method possible? [duplicate]

一曲冷凌霜 提交于 2019-12-25 02:47:14
问题 This question already has answers here : Explicitly calling a default method in Java (4 answers) Closed 5 years ago . Say I have two classes, A and B : class A { void method() { System.out.println("a.method"); } } class B extends A { @Override void method() { System.out.println("b.method"); } } After instantiating B as b , I can call B 's method like b.method() . I can also make B 's method call A 's method with super.method() . But what if A is an interface: interface A { default void method

What does super.<method-name> do in ruby?

故事扮演 提交于 2019-12-25 01:39:30
问题 With the following code: class ObjA def func puts "ObjA" end end module Mod def func puts "Mod" end end class ObjB < ObjA include Mod def func puts "super called" super puts "super.func called" super.func end end Running ObjB.new.func results in: ruby-1.9.2-p180 :002 > ObjB.new.func super called Mod super.func called Mod NoMethodError: undefined method `func' for nil:NilClass from test.rb:19:in `func' from (irb):2 I understand what super does - it calls the current method on the superclass.

What is (is there?) a purpose behind declaring a method twice when parent class appears to not change any properties?

旧街凉风 提交于 2019-12-25 01:05:50
问题 So I am looking at these respective classes (and subclasses)... public class Control{ public Control(){} public Control(String name, String type, ContainerControl owner){ //do stuff here } } public class ContainerControl extends Control{ public ContainerControl() { super(); } public ContainerControl(String name, String type, ContainerControl owner) { super(name, type, owner); controls = new Controls(); //exists somewhere else } } public class SSTab extends ContainerControl{ public SSTab(){

python multiple inheritance: avoid calling the constructors twice in diamond shape

三世轮回 提交于 2019-12-24 18:12:44
问题 Consider the following code: class A(object): def __init__(self): print("A.__init__") super(A, self).__init__() # 1 print("A.__init__ finished") class B(A): def __init__(self): print("B.__init__") super(B, self).__init__() # 2 print("B.__init__ finished") class C(A): def __init__(self): print("C.__init__") super(C, self).__init__() print("C.__init__ finished") class D(B, C): def __init__(self): print("D.__init__") print("Initializing B") B.__init__(self) # 3 print("B initialized") print(

Can System App access /data/data of other apps

萝らか妹 提交于 2019-12-24 14:39:33
问题 I am developing an app for the custom device. My app run from /system/priv-apps I need to access /data/data for other apps to give a cloud backup functionality. While searching I came across "android.permission.CONFIRM_FULL_BACKUP" permission but I couldn't find a way to get the content of that particular " /data/data/pkg_name ". I don't think that system apps have su permission so I can't call cp -R src dest Can anyone tell me regarding this? 来源: https://stackoverflow.com/questions/49463327

super() not letting me call the super constructor with parameters

吃可爱长大的小学妹 提交于 2019-12-24 04:45:11
问题 I want to call the super class' constructor that takes two arguments, so I call super(arguments), but the compiler says: "Constructor Person in class Person cannot be applied to given types; required: no arguments Found: Java.lang.String, int reason: actual and formal argument lists differ in length" I have no clue why this is happening. The call to super is the first line. The arguments match (but not to the compiler for some reason). Does anyone know what's going on? I'm using NetBeans, by