1
votes

I am working with Microsoft Outlook 2010 and with pyExchange. I am trying to list all the events scheduled between two dates as mentioned here in the docs. My code snippet is as below:

eventsList = service.calendar().list_events(
    start=timezone("Europe/London").localize(datetime(2015, 1, 12, 1, 0, 0)),
    end=timezone("Europe/London").localize(datetime(2015, 1, 14, 23, 0, 0)))

print eventsList
for event in eventsList:
    print "{start} {stop} - {subject}".format(
        start=event.start,
        stop=event.end,
        subject=event.subject
    )

I have created events in my calendar manually using Outlook as well as by using pyExchange.

But when ever I execute the code snippet above I only get the following traceback:

<pyexchange.exchange2010.Exchange2010CalendarEventList object at 0x02056550>
Traceback (most recent call last):
  File "C:\Users\p\Desktop\getEvent.py", line 41, in <module>
    for event in eventsList:
TypeError: 'Exchange2010CalendarEventList' object is not iterable

Any suggestion why this happening and how to solve it? Thanks.

1
It's happening because that object does not support iteration (see the source). You can iterate over e.g. eventsList.events instead.jonrsharpe

1 Answers

3
votes

It seems like the eventsList is not iterable, which means you can't open it Item per Item. This would mean that the eventsList is no List or String or any other iterable object.

You have to Iterate over the members instead:

for events in eventList.events:
    # do stuff

PS: The doc is 'unfinished' better read the source