超类继承中的Python非类型列表索引

超类继承中的Python非类型列表索引,python,inheritance,indexing,superclass,Python,Inheritance,Indexing,Superclass,我的程序中有3个类,我使用超类从两个基类继承变量。类A构建两个包含数字的列表,并绘制数字并在其函数中使用。为了索引要绘制的数字以及绘制的次数,该机制构建在类B的循环中。迭代次数由变量initX和algorithmIndex确定。对于循环的每次迭代,A类从每个ls1和ls2中绘制一个编号,索引为ls[initX]ls[initX]新类需要从A类和B类继承。但是initX和algorithmIndex在class New中给出一个Nonetype。我希望算法索引和非类型的值可以与B类中的值相同。我不

我的程序中有3个类,我使用超类从两个基类继承变量。类A构建两个包含数字的列表,并绘制数字并在其函数中使用。为了索引要绘制的数字以及绘制的次数,该机制构建在类B的循环中。迭代次数由变量
initX
algorithmIndex
确定。对于循环的每次迭代,A类从每个
ls1
ls2
中绘制一个编号,索引为
ls[initX]
ls[initX]
<代码>新类需要从
A类
B类
继承。但是
initX
algorithmIndex
class New
中给出一个
Nonetype
。我希望
算法索引
非类型
的值可以与
B类
中的值相同。我不知道为什么会发生这种情况,这两个变量不是从A类继承的吗?解决这个问题的好办法是什么

谢谢

这是我的密码:

ls1 = [1,2,3,4]
ls2 = [3,4,5,6]
algorithmIndex = None
initX = None

class A(object):
    def __init__(self, algorithmIndex, initX):
         self.algorithmIndex = algorithmIndex
         self.x = ls1[initX] #iniX is used as list index, which return a Nonetype in the new class.
         self.y = ls2[initX]
         self.ls1_history = []

         if self. algorithmIndex == 1:
             self.x1 = self.x
             self.ls1_history.append(self.x1)
         else:
             pass


class B(object):
   def __init__(self, arg):
         algorithmIndex = 1
         while algorithmIndex < 4: 
            initX = 0
            while initX < 4:
               self.q.append(A(algorithmIndex, initX)) #initX needs to be included as an argument in class A. 
               initX += 1
         algorithmIndex += 1

   def midpt(self):
         i = 0
         while i < 4:
            mid = self.q[i].ls1_history
            i+=1


class New(A,B):
    def __init__(self, arg, algorithmIndex, initX):
         A.__init__(self, algorithmIndex, initX)
         B.__init__(self, arg)
         self.initX = A.initX
         self.algorithmIndex = A.algorithmIndex

您发布的代码会产生不同的错误;请修复此问题。您尚未向我们展示如何创建
New
的实例。然而,你的课程有点奇怪。在
B
中,您有
self.q.append
,但该类没有定义
q
属性。在
New
中,什么是
B.arg
,您希望
A.initX
A.algorithmIndex
是什么?@PM2Ring感谢您的指出,我只是尽力使其简洁。将
initX
更改为0
 self.x = ls1[initX]
 TypeError: list indices must be integers or slices, not NoneType