- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
根据 http://docs.python.org/2/library/functions.html#super ,
If the second argument is omitted, the super object returned is unbound.
哪个是 super (类型)。
我想知道什么是无界的,什么时候是有界的。
最佳答案
您问题的其他答案( answer 、 answer )已经解释了绑定(bind)/未绑定(bind)这两个词的含义。
So my focus is to explain only the use of an unbound proxy object returned from the
super()
function (i.e. in the case it was used only with 1 argument).
获取未绑定(bind)对象的原因是以后绑定(bind)它。
特别是,对于从 super()
函数返回的未绑定(bind)对象,您可以使用其 __get__()
方法将其绑定(bind)到适当的对象,例如
super(C).__get__(c) # where C is a class and c is an object
为了说明这一点,让我们创建 3 个依赖类和 3 个对象 - 每个类一个:
class A:
def __init__(self, name):
self.name = name
def message(self, source):
print(f"From: {source}, class: A, object: {self.name}")
class B(A):
def __init__(self, name):
self.name = name
def message(self, source):
print(f"From: {source}, class: B, object: {self.name}")
class C(B):
def __init__(self, name):
self.name = name
def message(self, source):
print(f"From: {source}, class: C, object: {self.name}")
a = A("a")
b = B("b")
c = C("c")
现在在交互式控制台中,首先是为了理解事物:
>>> super(B) # unbounded (note 'None')
<super: __main__.B, None>
>>> super(B).__get__(b) # bounded to object b (note address)
<super: __main__.B, <__main__.B at 0xa9bdac0>>
>>> b # note: the same address
'<__main__.B at 0xa9bdac0>
然后——显示使用不同类/对象组合的结果
(在我们委托(delegate)方法 .message()
的例子中):
>>> super(B).__get__(b).message("super(B)")
From: super(B), class: A, object: b
>>> super(C).__get__(c).message("super(C)")
From: super(C), class: B, object: c
>>> super(B).__get__(c).message("super(B)")
From: super(B), class: A, object: c
最后是绑定(bind)和未绑定(bind)代理到适当类的示例:
>>> A.name = "Class A" # Preparing for it -
>>> B.name = "Class B" # creating some class attributes
>>> super(B).__get__(B).name # Proxy super(B) bounded to class B
'Class A'
>>> super(B).__get__(C).name # Proxy super(B) bounded to class C
'Class A'
>>> super(C).__get__(C).name # Proxy super(C) bounded to class C
'Class B'
关于python - python中的 'super object returned is unbound'是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22403897/
问题比较Java,但是我想在Android中实现: 假设有 3 个或更多类相互扩展: class A { ... int color; ... } class B extend
我知道标题听起来有点奇怪,但这正是我愿意做的。简单解释:A类是B类的子类,B类也是C类的子类>. 现在,所有这些类都包含方法m()。在我的 A 类中,这是我唯一可以访问的类,因为其他类仅在运行时可用,
我有一个 UIViewController 类 A 和 B。 A 使用以下方式加载 B:[A.view addSubView B.view]。 B 有一个带有“后退”按钮的导航栏。我想在单击时返回到
我有以下(第三方)类结构。我们将调用第三方项目 ProjectSeriously,并注意我使用 System.out.println 代替其他复杂的功能(100 行代码) . class A {
在下面的代码中,我从 Game 扩展了 MyGame。我有两个问题: 我们是否需要为所有render()、dispose()、pause()调用super方法 和 resize(w,h)?很多人都没有
例如,假设我想在调用 super.viewDidLoad() 时跳过一级。所以我希望能够做这样的事情: override func viewDidLoad() { super.super.vi
public class Faculty extends Employee { public static void main(String[] args) { new Fac
假设我有: class Superclass { //fields... methodA() {...} methodB() {...} ... } class Subclass exte
这个问题在这里已经有了答案: Why is super.super.method(); not allowed in Java? (22 个答案) 关闭 9 年前。 我怀疑我想做的事情是否可行。我有
我有一个实现 Initializable 的类。 public abstract class ExampleClass implements Initializable { public vo
我想知道,我有这个大数组,是否可以只在内存中使用一次而不是每个线程一次?以 stackoverflow 上的标签为例。他们几乎从不改变,为什么不为他们留下一个内存点呢?甚至可能将该数组永久保存在内存中
假设这三个类具有这个简单的层次结构: class A { func foo() { print("A") } } class B: A { override fu
有没有办法在 TypeScript 中调用 super.super.methodName。我想避免调用super.methodName,但我想调用二祖的methodName方法。 谢谢。 最佳答案 T
这个问题已经有答案了: When do I use super()? (11 个回答) 已关闭 7 年前。 package Geometry; public abstract class Geomet
我必须执行and()在我的实现 Predicate 的业务对象上. 出现问题的代码是 and() 行调用: Predicate predicate = new M
我有一个实现接口(interface)的抽象父类(super class): public abstract class FooMatrix implements Matrix { publi
我有四个 UIView:viewA 是 Root View ,它有 viewB 作为它的 subview 。 viewB 将 viewC 作为其 subview ,而 viewC 将 viewD 作为
有什么区别: class Child(SomeBaseClass): def __init__(self): super(Child, self).__init__() 和:
我有一个通用接口(interface) interface ListList extends List> .由于某些原因,我无法转换 ListList至 List> .有什么方法可以做到吗?为什么它不
我想调用带有两个参数的父类(super class)的构造函数,所以我调用了 super(arguments),但是编译器说: “类 Person 中的构造函数 Person 不能应用于给定类型; 要
我是一名优秀的程序员,十分优秀!