Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取一个wx listctrl列中的项目总和_Python_Wxpython - Fatal编程技术网

Python 获取一个wx listctrl列中的项目总和

Python 获取一个wx listctrl列中的项目总和,python,wxpython,Python,Wxpython,我这里有一个列表 self.list2 = wx.ListCtrl( self, wx.ID_ANY, wx.DefaultPosition, wx.Size( -1,100 ), wx.LC_REPORT|wx.LC_SORT_DESCENDING ) self.list2.InsertColumn(0,"Order ID") self.list2.InsertColumn(1,"Item ID") self.list2.

我这里有一个列表

self.list2 = wx.ListCtrl( self, wx.ID_ANY, wx.DefaultPosition, wx.Size( -1,100 ), wx.LC_REPORT|wx.LC_SORT_DESCENDING )
            self.list2.InsertColumn(0,"Order ID")
            self.list2.InsertColumn(1,"Item ID")
            self.list2.InsertColumn(2,"Item Price")
            self.list2.InsertColumn(3,"Item Qty")
            self.list2.Bind(EVT_LIST_ITEM_SELECTED,self.GetSelectedItems2)
            self.list2.Bind(EVT_LIST_DELETE_ITEM,self.delete_item)

现在,我正在尝试提出一个函数,它将遍历给定的列表,并获得所述列表中所有商品价格的总和。。。我不知道该怎么做

假设您在“商品价格”列中有某种价格,那么应该这样做:

total = sum(float(self.GetItem(row, 2).GetText()) for row in range(self.GetItemCount()))

实际上,您应该使用十进制模块对美元金额进行求和,而不是浮动。否则,您可能会遇到舍入问题。