Microsoft团队在for循环中加载有效负载

2024-05-18 07:54:10 发布

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

我有一个要迭代的项目列表,并包含在要发送给团队的有效负载中,但只有列表中的第一个项目被发布

items = ["first", "second", "third", "fourth"]

for item in items:
    payload = {
      "@type": "MessageCard",
      "@context": "http://schema.org/extensions",
      "themeColor": "FFFFFF",
      "summary": "a short description of things",
      "text": str(item)
    }

目前只有first被张贴在一张信息卡中。有没有办法在一张卡片上列出所有项目


Tags: 项目in列表fortypeitems团队item
2条回答

这是你想要的吗

payload = {
      "@type": "MessageCard",
      "@context": "http://schema.org/extensions",
      "themeColor": "FFFFFF",
      "summary": "a short description of things",
      "text": str(items)
    }

希望我能帮忙

如果希望发送4个单独的有效载荷,则需要制作一个数组:

items = ["first", "second", "third", "fourth"]
payloads = []
for item in items:
    payload = {
      "@type": "MessageCard",
      "@context": "http://schema.org/extensions",
      "themeColor": "FFFFFF",
      "summary": "a short description of things",
      "text": str(item)
    }
    payloads.append(payload)

如果您想要一个有效负载,其中所有项目都由某个字符或字符串(此处为逗号)分隔:

items = ["first", "second", "third", "fourth"]
payload = {
    "@type": "MessageCard",
    "@context": "http://schema.org/extensions",
    "themeColor": "FFFFFF",
    "summary": "a short description of things",
    "text": ','.join(items)
}

相关问题 更多 >