from Tkinter import *
class Application(Frame):
def __init__(self, master):
super(Application, self).__init__(master)
self.grid()
self.bttnClicks = 0
self.createWidgets()
def createWidgets(self):
self.bttn = Button(self)
self.bttn["text"] = "number of clicks"
self.bttn["command"] = self.upadteClicks
self.bttn.grid()
def upadteClicks(self):
self.bttnClicks += 1
self.bttn["text"] = "number of clicks " + str(self.bttnClicks)
root = Tk()
root.title("button that do something")
root.geometry("400x200")
app = Application(root)
root.mainloop()`
Run Code Online (Sandbox Code Playgroud)
这就是错误:
super(Application, self).__init__(master)
TypeError: super() argument 1 must be type, not classobj
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?该代码在 python 3.XX 中运行良好,但在 python 2.XX 中则不然。
为什么我们使用的时候不需要自引用super().__init__?(比如下面第9行)
class labourers():
def __init__(self,name,department,salary):
self.name = name
self.department = department
self.salary = salary
class managers(labourers):
def __init__(self,name,department,salary,numberofpeople):
super().__init__(name,department,salary)
self.numberofpeople = numberofpeople
Run Code Online (Sandbox Code Playgroud) 让我们考虑以下虚拟示例:
class A:
def __init__(self, a):
self.a = a
self.backup_a = a
def reset_a(self):
self.a = self.backup_a
print ('Stop touching my stuff!')
class B(A):
def __init__(self, a, b):
super().__init__(a)
self.b = b
var = A(2)
var.reset_a()
var = B(2, 4)
var.f()
Run Code Online (Sandbox Code Playgroud)
要添加一个方法,该方法使用fromB方法,boh 语法与or一起工作。哪一种更正确,为什么?reset_aAsuper().self.
class B(A):
def __init__(self, a, b):
super().__init__(a)
self.b = b
def f(self):
self.reset_a()
Run Code Online (Sandbox Code Playgroud)
或者
class B(A):
def __init__(self, a, b):
super().__init__(a)
self.b = b
def f(self):
super().reset_a()
Run Code Online (Sandbox Code Playgroud) 我在 Redshift 中有一些值,它们是超级数据类型,看起来像["a", "b", "c"].
我正在尝试编写一个类似于array_joinAthena SQL 中的函数,它将所有部分与分隔符组合在一起。因此,对于上面的示例,它将返回 varchar 值a, b, c。
如果需要,我有权创建 python/sql 用户定义函数,但 python UDF 无法读取超级数据类型。
我尝试将数组转换为子查询表并使用partiql来取消嵌套,但是redshift不允许我在领导者或其他东西上取消嵌套子查询。我的方法是将这些值重新列表在一起。我能够创建一个表而不是子查询,并成功取消嵌套/listagg 值,但 sql 函数不允许使用多个命令。
我还尝试使用涉及 seq_0_5 视图的在线指南将 sql 数组拆分为行,并将代码调整为超级函数。这不起作用,因为当我尝试使用不等式连接表时,redshift 断开了我的连接。
如果我已经接近了,请告诉我,但感觉我已经走进了两个死胡同。
arrays type-conversion super user-defined-functions amazon-redshift
下面出现错误 TS2556,如何修复?
class Test {
constructor(x: number) {}
}
class Test2 extends Test {
constructor(...args) {
super(...args); // TS2556
}
}
Run Code Online (Sandbox Code Playgroud)
或者,如果您使用 jsdoc 和 tsc 进行类型检查:
class Test {
constructor(x: number) {}
}
class Test2 extends Test {
constructor(...args) {
super(...args); // TS2556
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个超级班FTM:
class FTM:
def __init__(self,word_weighting = 'normal'):
self.word_weighting = word_weighting
def get_sparse_global_term_weights(self, word_weighting):
pass
Run Code Online (Sandbox Code Playgroud)
以及继承自的子类FTM:
class FLSA(FTM):
def __init__(self, word_weighting='normal'):
super().__init__(word_weighting = word_weighting)
self.sparse_global_term_weighting = super().get_sparse_global_term_weights(word_weighting = super().word_weighting)
Run Code Online (Sandbox Code Playgroud)
运行此代码,我收到以下错误:
AttributeError: 'super' object has no attribute 'word_weighting'
Run Code Online (Sandbox Code Playgroud)
我已经初始化了该属性。为什么我会收到此错误?
我试图弄清楚 super 在 JavaScript 中是如何工作的。我有一个想法,但我不确定它的准确性,所以我需要一些帮助。
class A {
}
class B extends A {
constructor() {
super();
}
}
class C extends B {
constructor() {
super();
}
}
new C
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,“new”运算符创建一个对象并将其链接到构造函数 C 的原型,构造函数 C 的隐藏属性“thisArg”现在指向新创建的对象
+---------------------+
| function object |
+---------------------+
| - code |
+---------------------+
| - outerScope |
+---------------------+
| - thisArg |
+---------------------+
| - [[Prototype]] |
+---------------------+
| + prototype |
+---------------------+
| + length |
+---------------------+
| + name |
+---------------------+
Run Code Online (Sandbox Code Playgroud)
注意:隐藏属性 …
我知道之前已经讨论了很多次,但是从来没有对"引擎盖下"发生的事情做出任何解释.
任何人都可以提供一个详细的解释,为什么注释 - 在最后一行代码中引起错误?我知道那个对象.__ init__没有任何参数,但是为什么代码在注释掉行时会起作用?
class A:
def __init__(self, a):
print("A constructor")
super().__init__(a)
self.a = a
print("A constructor end")
class B:
def __init__(self, b):
print("B constructor")
super().__init__()
self.b = b
print("B constructor end")
class C(A, B):
def __init__(self, x):
super().__init__(x)
c = C(42)
#a = A(33)
Run Code Online (Sandbox Code Playgroud) 不会super(type, object)和super(supertype, type)所有人都返回超类的对象type(supertype)吗?有什么不同?
我相信,在Perl中调用父类的构造函数的规范方法是:
package Child;
our @ISA = 'Parent';
sub new {
my $class = shift;
my @args = @_;
my $self = $class->SUPER::new(@args);
return $self;
}
Run Code Online (Sandbox Code Playgroud)
但是,如果Parent没有明确定义new函数(但Grandparent确实如此),则此构造似乎不起作用.
例如,就是这种情况Net::FTP::File.
tq84_ftp.pm:
package tq84_ftp;
use warnings;
use strict;
our @ISA = qw(Net::FTP::File);
sub new {
my $class = shift;
my $self = $class->SUPER::new('localhost')
or die($@);
return $self;
}
1;
Run Code Online (Sandbox Code Playgroud)
script.pl:
use tq84_ftp;
tq84_ftp->new();
Run Code Online (Sandbox Code Playgroud)
输出:
Can't locate package Net::FTP::File for @tq84_ftp::ISA at tq84_ftp.pm line 10. …Run Code Online (Sandbox Code Playgroud) super ×10
python ×5
class ×3
inheritance ×3
python-3.x ×3
constructor ×2
oop ×2
arrays ×1
extends ×1
javascript ×1
jsdoc ×1
perl ×1
python-2.7 ×1
spread ×1
tkinter ×1
typescript ×1