gpt4 book ai didi

python - 在 gtk.ListStore 中指定字段的更好方法

转载 作者:行者123 更新时间:2023-12-01 05:54:25 27 4
gpt4 key购买 nike

我有一个包含很多字段的 ListStore,其中大部分都是相同的:

store = gtk.ListStore(str,str,str,str,str,str,str,str,
gtk.gdk.Pixbuf,gtk.gdk.Pixbuf,gtk.gdk.Pixbuf,gtk.gdk.Pixbuf,
gtk.gdk.Pixbuf,gtk.gdk.Pixbuf,gtk.gdk.Pixbuf,gtk.gdk.Pixbuf,
gtk.gdk.Pixbuf,gtk.gdk.Pixbuf,gtk.gdk.Pixbuf,gtk.gdk.Pixbuf,
gtk.gdk.Pixbuf,gtk.gdk.Pixbuf,str,)

还有比这种可怕的大量重复更好的方法吗?

编辑:所以结果是:

store = gtk.ListStore( *(8*(str,)+14*(gtk.gdk.Pixbuf,)+(str,)) )

我猜可读性较差,但编程适应性更强

最佳答案

  1. 如果您可以控制 ListStore 代码,请将它们打包到 namedtuple 中,并确保它们不会遮盖内置名称。
  2. 如果您无法控制 ListStore 代码,请将它们打包到一个元组中,并通过 gtk.ListStore(*yourtuple) 解压缩参数。

关于python - 在 gtk.ListStore 中指定字段的更好方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13181424/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com