我在用Image. open(Path),函数时(这里的path是一张图片的路径,我用path代替了),出现了下面这些问题,各位大佬帮我看看,这个该怎么解决啊
AttributeError: 'list' object has no attribute 'seek'
AttributeError: 'list' object has no attribute 'read'

关于Python中的Image. open函数的使用出现的问题
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- 辉煌仪奇 2021-10-26 11:27关注
猜测你的代码如下
path定义成了一个listfrom PIL import Image Path=['./123.png'] print(Image. open(Path))
报错如下Traceback (most recent call last): File "F:\project\Question\venv\lib\site-packages\PIL\Image.py", line 2972, in open fp.seek(0) AttributeError: 'list' object has no attribute 'seek' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "F:\project\Question\main.py", line 2607, in <module> print(Image. open(Path)) File "F:\project\Question\venv\lib\site-packages\PIL\Image.py", line 2974, in open fp = io.BytesIO(fp.read()) AttributeError: 'list' object has no attribute 'read'
修改如下即可,
from PIL import Image Path=['./123.png'] for i in Path: print(Image. open(i))
from PIL import Image Path='./123.png' print(Image. open(Path))
运行成功通过
有帮助请采纳,有问题继续交流,你的采纳是对我回答的最大的肯定和动力
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用