python-3.x - Python 下载带有请求与请求、枕头和 BytesIO 的图像。后者的优势是什么?
问题描述
使用 Python 下载图像有两种可行的解决方案。
1.
import requests
response = requests.get(img_url)
with open('image.png', 'wb') as f:
f.write(response.content)
import requests
from io import BytesIO
from PIL import Image
response = requests.get(img_url)
im = Image.open(BytesIO(response.content))
im.save('image.png')
为什么要打扰第二个(我在其他人的代码中看到过)?与第一种简洁明了的方法相比,它有什么优势吗?
解决方案
推荐阅读
- python - 如何将块的结果放入 csv 列
- flutter - Different between shared preference and using redux
- postgresql - 自动检测 PostgreSQL 的主/从代理
- nuget - Artifactory nuget push - 不存在的用户(API 密钥/访问令牌)
- rxjs - 茉莉花测试期间出现意外错误(可观察到)
- makefile - 覆盖包含(删除路径)
- swift - 快速刷新标签栏控制器以在标签栏项目上显示徽章
- python-3.x - 如果所有行只包含标点符号,如何检查和删除熊猫列?
- docker - 使用 Transfer for on-premises 选项传输文件
- mongodb - MongoDB:必须每个索引都以 shardkey 为前缀