我想从类的另一个函数中获取列表,但是这个函数返回空列表。我不明白如何连接这个函数而不丢失列表数据(
from classCR import *
...
if Main == 1:
LenArray.InputArr(a)
if Main == 2:
LenArray.RandomArr(a)
if Main == 3:
LenArray.GetItemArr(1)
和等级CR
class ClassArray:
def __init__(self,LenghtArray):
self.LenghtArray = LenghtArray
self.ArrayInpList = []
self.ArrayRandList = []
def InputArr(self,LenghtArray):
for i in range(self.LenghtArray):
self.ArrayInpList.append(int(input('Input value of '+str(i)+': ')))
print(self.ArrayInpList)
def RandomArr(self,LenghtArray):
for i in range(self.LenghtArray):
self.ArrayRandList.append(random.randint(-30,30))
print(self.ArrayRandList)
def GetItemArr(self):
print(self.ArrayRandList)
在def GetItemArr中,我想从def RandomArr获取list的值。但是当我在主代码LenArray.GetItemArr()中更改为条件2时-它可以工作…
目前没有回答
相关问题 更多 >
编程相关推荐