我有事件,人们可以属于一个事件。所以我有一个看起来像这样的事件类:
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)
这对我来说毫无意义,我做错了什么?(我相信有很多)