我想在基类(FooBase
)中使用派生类(Foo
)的类属性执行某些操作。我想用Python 3 。
class BaseFoo:
#felder = [] doesn't work
def test():
print(__class__.felder)
class Foo(BaseFoo):
felder = ['eins', 'zwei', 'yep']
if __name__ == '__main__':
Foo.test()
也许有不同的方法吗?
答案 0 :(得分:1)
您需要将Sub CopyArray()
Dim x As Variant
Dim y As Variant
x = Array(1, 2, 3)
y = Application.Transpose(x) '<~~ Transpose it
For i = LBound(y) To UBound(y)
Debug.Print y(i, 1)
Next i
End Sub
设为class method,并为其提供一个可用于访问该类的参数;通常这个arg名为test
。
cls
<强>输出强>
class BaseFoo:
@classmethod
def test(cls):
print(cls.felder)
class Foo(BaseFoo):
felder = ['eins', 'zwei', 'yep']
if __name__ == '__main__':
Foo.test()