python - subpods.img 的返回类型
问题描述
我希望我的代码查询 wolfram 并获取它返回的图像。但是 wolfram API 的返回类型不符合我的要求。
subpods.img 返回一个类映射对象。Discord 只能发送图像文件。当返回类型不兼容时,我该怎么做。我的代码如下所示。
当我实际尝试打印 pod.img 的类型时,它表明它实际上来自类映射。我应该在这里做什么?
async def printImgPod(ctx, img, title):
newmessage = await ctx.send("\__\**" + title + ":\**__\n" + "`" ,file= img)
messageHistory.add(newmessage)
@bot.command()
< all the rest of the code for the command >
res = waclient.query(query)
if len(list(res.pods)) > 0:
for pod in res.pods:
if pod.text:
<code for printing text in pod>
else:
for sub in pod.subpods:
if sub.img:
await printImgPod(ctx.message.channel, sub.img, pod.title)
解决方案
它看起来像是sub.img
一个字典的迭代器。要获取图像的 URL,请尝试
for sub in pod.subpods:
for img in sub.img:
await printImgPod(ctx.message.channel, img['@src'], pod.title)
推荐阅读
- linux - 如何以字母顺序的另一个顺序访问或排序目录的文件?
- spring - 如何发布到 Spring Boot 执行器?
- node.js - Jest 测试 WebSocket 客户端 API
- html - 如何一张一张地滑入图像?
- java - 创建名为“hypermediaRepresentionModelProcessorConfigurator”的 bean 时出错
- php - 根据另一个数字增加一个数字
- php - Symfony 4 EasyAdminBundle:纯密码的编码和保存问题
- java - 从 mysql 检索图像并在 JSP 上显示
- python - Python-在Tkinter中的同一帧中绘制多个图
- javascript - 如何在td内画圆?