我有事件,人們可以屬於事件。所以我有一個事件類,看起來像:試圖將項目追加到Python中的列表中,但其代理奇數
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)
這對我來說沒有意義,它比我做錯了什麼? (我確定有很多)
你的問題我不清楚..你能也顯示預期的輸出?你想做什麼? –