Есть ли способ игнорировать нулевые значения в списке python? - PullRequest
1 голос
/ 24 апреля 2020

Я работаю над тем, чтобы вытащить участников календарного события из Google и обнаружил, что, если у события нет участника, происходит сбой для l oop.

    for calendar_id in me:
        count = 0
        #print('\n%s' % calendar_id)
        eventsResult = service.events().list(
            calendarId=calendar_id,
            timeMax=now,
            timeMin=end_date).execute()
            #orderBy='startTime').execute()
        #events = eventsResult.get('items', [])
        #events = eventsResult.get('items', [])

        events = service.events().list(calendarId=calendar_id).execute()
        events = events.get('items', [])
        for event in events:
            start = event['start'].get('dateTime')
            print('\n' + event['summary'] + " " + "(Calendar - " + calendar_id + ")")
            for attendees in event['attendees']:
                attid = event.get('attendees')
                atte = attendees.get('email')
                try:
                    attid = event.get('attendees')
                except Exception as e:
                    print("No attendees", e)
                try:
                    atte = attendees.get('email')
                except Exception as e:
                    print("No email found", e)

1 Ответ

3 голосов
/ 24 апреля 2020

Это поможет вам в течение l oop продолжить

for attendees in event['attendees']:
    try:
        attid = event.get(attendees)
    except Exception as e:
        print("No attendees", e)
    try:
        atte = attendees.get('email')
    except Exception as e:
        print("No email found", e)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...