2024-10-04 01:22:16 发布
网友
我有这个代码,一个图像列表。在
self.image0 = gtk.Image() self.image1 = gtk.Image() self.image2 = gtk.Image() [...] self.image20 = gtk.Image() self.img = # list of all this 20 images. How to write this?
我在找一种用短线写这张单子的方法。在
你能帮我吗?在
谢谢
使用list comprehension:
self.img = [gtk.Image() for i in range(20)]
您可以使用list comprehensions如:
self.img = [gtk.Image() for _ in xrange(20)]
图像可以通过instance.img[0]访问,但不能再通过instance.image0访问。在
instance.img[0]
instance.image0
使用list comprehension:
您可以使用list comprehensions如:
图像可以通过
instance.img[0]
访问,但不能再通过instance.image0
访问。在相关问题 更多 >
编程相关推荐