从lis检索元素

2024-10-02 00:36:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我在一个列表中插入条目,并使用heapq来存储这些条目。下面是我的代码。。我需要根据第一列值(ut)对列表进行排序,并在gui上获得前10项。当我试图从列表中检索数据时(即自我.top10ele)使用下面的“for循环”,我一次只能得到一行。另外,我无法删除以前的数据。。有人能告诉我我哪里出错了吗?在

class MyAppl:
    def __init__(self):
            # hastable, lists, tablesize defined 
            self.dir_list = []
            self.dir_list = os.getpids()
            for number in self.dir_list:
                    self.proc_path = /proc/somepath;
                    self.f = open(self.proc_path,'r').read()
                    self.ut = self.f.split()[13]
                    self.st = self.f.split()[12]                 
                    item = Proc_struct.Proc_s(ut,st)
            self.insert(item)

#Hashing here 

def heap(self):
            heap = []
            for i in range(self.tableSize):
                    for j in range(len(self.hashTable[i])):
            heapq.heappush(heap,(self.hashTable[i][j].ut,self.hashTable[i][j].st))
            self.top10ele = (heapq.nlargest(15,heap))

            #for i in range(self.tableSize):
                for k in self.top10ele:
                      self.text.insert(INSERT,k[0],'val')
                      self.text.insert(END, "\t\t")
                      self.text.insert(INSERT,k[1],'val')
                      self.text.insert(END,"\t\t\t")
                      self.text.insert(INSERT,k[2],'val')
                      self.text.insert(END,"\t")
                      self.text.insert(END,"\n")

Tags: textinself列表fordirproclist

热门问题