我有一些事件,人们可以属于一个事件。因此我有一个事件类,看起来像这样:
class Event():
name = ""
people = []
我还有一个全局变量来保存所有的事件。
events = []
现在我正在尝试将原始数据处理成事件和参与者:
# If there are missions, add the events
for m in wiki.missions:
foundEvent = False
for e in events:
if e.name == m:
foundEvent = True
foundPerson = False
for p in e.people:
if p.rawName == person.rawName:
foundPerson = True
if not foundPerson:
e.people.append(person)
print "Added " + person.display + " to " + m + " (" + str(len(e.people)) + ")"
if foundEvent == False:
event = Event()
event.name = m
event.people.append(person)
print "New " + person.display + " to " + m + " (" + str(len(event.people)) + ")"
events.append(event)
event = None
根据我的打印语句,我可以看到谁被添加到现有的事件中以及何时和谁创建了新事件。奇怪的是,每个事件中的人数总是增加所有事件中的人数。
New Joseph M. Acaba to STS-119 (1)
New Joseph M. Acaba to Soyuz TMA-04M (2)
New Joseph M. Acaba to Expedition 31 Expedition 32 (3)
Added Dominic A. Antonelli to STS-119 (4)
New Dominic A. Antonelli to STS-132 (5)
Added Richard R. Arnold to STS-119 (6)
这对我来说毫无意义,那么我做错了什么呢?(我确定有很多错误)