如何使用python循环在Google日历API中添加数据参与者?

2024-05-13 19:09:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为我的项目使用谷歌日历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]},
      ],

我得到了无效的语法

如何解决这个问题?多谢各位


Tags: 数据项目comapiexampleemail格式静态
1条回答
网友
1楼 · 发布于 2024-05-13 19:09:53

将代码更改为以下内容:

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

然后,当你按照你想要的方式构建字典时,只要说:

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

希望这有帮助

相关问题 更多 >