0
我已经定义了具有多个属性的对象的getString()..蟒蛇:使用选择框来获取数据,除了
class thing(object):
def __init__(self, type, name, attrA, attrB, attrC):
self.type = type
self.name = name
self.attrA = attrA
self.attrB = attrB
self.attrC = attrC
可以说,那么我的事情的清单
self.things=[thing('car','fred',1,2,3),
thing('car','george',a,b,c),
thing('truck','bob',6,7,8),
thing('truck','tom',x,y,z)
]
然后,我填充选择框中的某些项目从该列表
for each in self.things:
if each.type == 'car':
self.choiceCar.Append(item=each.name)
当用户从下拉列表中选择鲍勃我有一个n事件
def EvtChoice(self,event):
self.Name = event.GetString()
这将捕获选择的名称,但是如何获取其他属性?什么我目前做的是
for each in self.items:
if self.Name == each.name
#Get other things here
我的想法是,如果我的列表变大则因为用户已经选择了我想要的特定项目这个循环通过我的整个列表会变得非常低效的,真正不必要的。我认为我应该能够做的就是获得所选项目的索引,但我不知道该怎么做,或者即使这是正确的方式去做。
正是我需要的。谢谢 – ccwhite1 2011-06-02 14:31:07