【问题标题】:How to add data attendees Google Calender API with python looping?如何使用 python 循环添加数据参与者 Google Calendar API?
【发布时间】:2020-06-03 15:01:01
【问题描述】:

我正在为我的项目使用 Google 日历 API 创建“事件日历”。要使用 python 将参与者添加到我的特定活动,API 需要以下格式的数据。

这就是静态和成功

 'attendees': [
    {'email': 'lpage@example.com'},
    {'email': 'sbrin@example.com'},
  ],

我想从数据库中获取数据并在 python 中使用循环“For”输入电子邮件

      'attendees': [
        myCursor.execute("SELECT email from calendar;")
        records = myCursor.fetchall()
        for row in records:
        {'email': row[0]},
      ],

我的语法无效

如何解决这个问题?谢谢你

【问题讨论】:

    标签: python arrays for-loop google-api fetch


    【解决方案1】:

    把你的代码改成这样:

    myCursor.execute("SELECT email from calendar;")
    records = myCursor.fetchall()
    attendees = [
        {'email': row[0]} for row in records
    ]
    

    然后在按照您的意图构建字典时,只需说:

    {
        ...
        'attendees': attendees,
        ...
    }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多