【发布时间】:2019-05-05 10:32:15
【问题描述】:
我在 Python 中有下一个代码:
class Base_class():
def __init__(self):
pass
# this is the method where I need help
def compress(variable?,index?):
somecode()
class Derived_class_1():
def __init__(self,somelist):
self.A = []
self.B = []
for item in somelist:
if item == 1:
self.A.append([1,0])
self.B.append([0,1])
else:
self.A.append([1,0])
self.B.append([1,0])
class Derived_class_2():
def __init__(self,somelist):
self.A = []
self.B = []
for item in somelist:
if item == 1:
self.A.append([1,0])
self.B.append([1,0])
else:
self.A.append([1,0])
self.B.append([0,1])
我需要能够在基类的 compress 方法中访问每个实例值并根据索引返回一维列表,因为实例变量对于列表中的每个元素都有两个可能的值。我需要将压缩方法设为一类吗?如果是这样,我怎样才能使它成为可能?
【问题讨论】:
-
这是一个懒惰的不回答,但观看 this video 会对您有所帮助。
标签: python class inheritance instance derived-class