N
nick
Ok I'm more than willing to admit it's probably me but I am struggling
with what appears to be a weird scope issue.
If you look at the code below I believe day 2 should only contain a
single event. But when you run the prog it prints the events from day
1 as well.
Any advice greatly appreciated.
class Day:
name = None
events = []
eventD = {}
class Event:
start = ''
end = ''
desc = ''
def loadMonth():
#Create Day one
day1 = Day()
day1.name = 'day1'
#Create first event for day one
event1 = Event()
event1.start = '10:00'
event1.end = '12:00'
event1.desc = 'event1'
day1.events.append(event1)
#Create second event for day one
event2 = Event()
event2.start = '14:00'
event2.end = '16:00'
event2.desc = 'event2'
day1.events.append(event2)
#Create a second day
day2 = Day()
day2.name = 'day2'
#Create a single event for day two
event3 = Event()
event3.start = '10:00'
event3.end = '12:00'
event3.desc = 'event3'
day2.events.append(event3)
#print day names to show they are different days
print day1.name
print day2.name
#print events for day 2 ONLY and it shows all day one as well ??????
for event in day2.events:
print event.desc
if __name__ == '__main__':
loadMonth()
with what appears to be a weird scope issue.
If you look at the code below I believe day 2 should only contain a
single event. But when you run the prog it prints the events from day
1 as well.
Any advice greatly appreciated.
class Day:
name = None
events = []
eventD = {}
class Event:
start = ''
end = ''
desc = ''
def loadMonth():
#Create Day one
day1 = Day()
day1.name = 'day1'
#Create first event for day one
event1 = Event()
event1.start = '10:00'
event1.end = '12:00'
event1.desc = 'event1'
day1.events.append(event1)
#Create second event for day one
event2 = Event()
event2.start = '14:00'
event2.end = '16:00'
event2.desc = 'event2'
day1.events.append(event2)
#Create a second day
day2 = Day()
day2.name = 'day2'
#Create a single event for day two
event3 = Event()
event3.start = '10:00'
event3.end = '12:00'
event3.desc = 'event3'
day2.events.append(event3)
#print day names to show they are different days
print day1.name
print day2.name
#print events for day 2 ONLY and it shows all day one as well ??????
for event in day2.events:
print event.desc
if __name__ == '__main__':
loadMonth()