如何获取gtk.ListStore的项数/行数/长度/计数

1 投票
1 回答
2177 浏览
提问于 2025-04-18 11:31

考虑这个例子:

import pygtk
pygtk.require('2.0')
import gtk

initarr = [ "aa", "bb", "xx" ]

liststore1 = gtk.ListStore(str)
for item in initarr:
  liststore1.append([item])

# one more:
liststore1.append(["whatever"])

# how to get length/size of liststore1 at this point?

正如评论所说的 - 我该如何在这段代码结束时获取 liststore1 的长度或大小呢?

1 个回答

2

只需要简单地用 print len(liststore1) 这行代码。

如果你想要计算列表中特定的项目:

l = ["foo","foo","bar"]
print l.count("foo")
2

撰写回答