python中一个class调用另一个class的print问题?

0
python新手,不是很清楚类的调度。我已经构造了一个limited stack的类。

class LimitStack():

def __init__(self,size,initValue):

self.size = size

self.stack = [initValue]*size

self.head = size -1

def __str__(self):

return str(self.stack)

def push(self,ele):

self.head = 0 if (self.head + 1 >= self.size) else self.head + 1

self.stack[self.head] = ele

def top(self):

return self.stack[self.head]

def get(self,idx):

#Get the element of certain index (index 0 starts from the last pushed element)

if (idx >= 0 and idx < self.size):

pos = (self.size+self.head-idx) if (self.head-idx < 0) else (self.head - idx)

return self.stack[pos]

然后我又构建了一个新的class DPcache,是一个字典结构,其中需要调用limitstack。

class DPcache():

def __init__(self,dictionary):

self.dict = {}

self.dictionary = dictionary

def __str__(self):

return str(self.dict)

#Push the mth cuttings

def push(self,cuttings,taul):

#add words to cache if they first appear in our view

for cutting in cuttings:

if cutting[0] not in self.dict.keys():

self.dict[cutting[0]] = LimitStack(taul,0)

希望输出的结构就是类似

{'得': [0,0,0,0],'心得':[0,0,0,0]}

堆栈是为了之后做迭代用的。

现在问题是print的时候输出

{'得': <LimitStack.LimitStack object at 0x0000006AD97F19E8>}的格式。
已邀请:

要回复问题请先登录注册