super

How does derived class arguments work in Python?

╄→гoц情女王★ 提交于 2020-04-17 19:08:45
问题 I am having difficulty understanding one thing in Python.I have been coding in Python from a very long time but there's is something that just struck me today which i struggle to understand So the situation goes like this I have a mixin and a view class Mixin: def get_session(self,request,*args,**kwargs): print(self) #should be the instance passed print(request) #should be the request object passed but it's also an instance class View: def get(self,request,*args,**kwargs): self.get_session

How does derived class arguments work in Python?

China☆狼群 提交于 2020-04-17 19:04:10
问题 I am having difficulty understanding one thing in Python.I have been coding in Python from a very long time but there's is something that just struck me today which i struggle to understand So the situation goes like this I have a mixin and a view class Mixin: def get_session(self,request,*args,**kwargs): print(self) #should be the instance passed print(request) #should be the request object passed but it's also an instance class View: def get(self,request,*args,**kwargs): self.get_session

How does derived class arguments work in Python?

我的梦境 提交于 2020-04-17 19:03:15
问题 I am having difficulty understanding one thing in Python.I have been coding in Python from a very long time but there's is something that just struck me today which i struggle to understand So the situation goes like this I have a mixin and a view class Mixin: def get_session(self,request,*args,**kwargs): print(self) #should be the instance passed print(request) #should be the request object passed but it's also an instance class View: def get(self,request,*args,**kwargs): self.get_session

Why do we not need to include self in super()?

╄→гoц情女王★ 提交于 2020-04-11 08:31:27
问题 Why in super() keyword, can we omit self ? What if we don't omit it? class A: def __init__(self, var1, var2): """ some code """ class B(A): def __init__(self, varA, varB): super().__init__(varA, varB) """ some code """ 回答1: class Rectangle: def __init__(self, length, width): self.length = length self.width = width def area(self): return self.length * self.width def perimeter(self): return 2 * self.length + 2 * self.width class Square(Rectangle): def __init__(self, length): super(Square, self)

java中super 的两种用法

梦想的初衷 提交于 2020-04-10 03:14:09
通过用 static 来定义方法或成员,为我们编程提供了某种便利,从某种程度上可以说它类似于 C 语言中的全局函数和全局变量。但是,并不是说有了这种便利,你便可以随处使用,如果那样的话,你便需要认真考虑一下自己是否在用面向对象的思想编程,自己的程序是否是面向对象的。 好了,现在开始讨论 this&super 这两个关键字的意义和用法。 在 Java 中, this 通常指当前对象, super 则指父类的。当你想要引用当前对象的某种东西,比如当前对象的某个方法,或当前对象的某个成员,你便可以利用 this 来实现这个目的,当然, this 的另一个用途是调用当前对象的另一个构造函数,这些马上就要讨论。如果你想引用父类的某种东西,则非 super 莫属。由于 this 与 super 有如此相似的一些特性和与生俱来的某种关系,所以我们在这一块儿来讨论,希望能帮助你区分和掌握它们两个。 在一般方法中 最普遍的情况就是,在你的方法中的某个形参名与当前对象的某个成员有相同的名字,这时为了不至于混淆,你便需要明确使用 this 关键字来指明你要使用某个成员,使用方法是 “this. 成员名 ” ,而不带 this 的那个便是形参。另外,还可以用 “this. 方法名 ” 来引用当前对象的某个方法,但这时 this 就不是必须的了,你可以直接用方法名来访问那个方法

super respondsToSelector: returns true but actually calling super (selector) gives “unrecognized selector sent to instance”

旧时模样 提交于 2020-02-13 04:09:51
问题 OK, I am a little confused. I have a subclass of UIScrollView, which is my attempt at a horizontally scrolling "table view" like UI element. UIScrollView itself sets up UIGestureRecognizers it uses internally, and it appears to set itself up as the delegate for those UIGestureRecognizers. I also have my own UIGestureRecognizer setup on my horizontal table elements/cells and my own class set as delegate for my own UIGestureRecognizer. Since my class is a subclass of UIScrollView, at runtime,

super respondsToSelector: returns true but actually calling super (selector) gives “unrecognized selector sent to instance”

巧了我就是萌 提交于 2020-02-13 04:09:13
问题 OK, I am a little confused. I have a subclass of UIScrollView, which is my attempt at a horizontally scrolling "table view" like UI element. UIScrollView itself sets up UIGestureRecognizers it uses internally, and it appears to set itself up as the delegate for those UIGestureRecognizers. I also have my own UIGestureRecognizer setup on my horizontal table elements/cells and my own class set as delegate for my own UIGestureRecognizer. Since my class is a subclass of UIScrollView, at runtime,