python - 在python中解析包含图像的文件时出现EOF
问题描述
我不明白为什么我在这里收到 EOF 错误。有人可以帮忙吗?在这里,我正在尝试遍历包含 3 个要显示的图像的文件夹“Flowers”,但无论如何我都会收到 EOF 错误
此外,当我仅显示 1 张图像时,未注释的 2 行代码有效。我想显示所有图像,我该怎么做?
解决方案
WHY : EOF 错误是由缺少for-loop
块引起的。a 的语法for-loop
是:
for item in collection:
# do something here..
# do more stuff here..
或者如果for-loop
为空,则需要指定pass
.
for item in collection:
#do nothing
pass
在您的代码中,没有要执行的内容,因此,它需要一个pass
关键字。
目标:说了以上,我认为这就是你想要做的:
image_path = "C:\\Users\PC\\Desktop\\Flowers\\{}"
images = ["img1.jpg", "img2.jpg", "img3.jpg"]
for image_name in images:
image = Image.open(image_path.format(image_name))
image.show()
推荐阅读
- python - Apache 服务器未启动
- c# - 使用 DbContext 和 Load 加载到内存中的数据库条目会发生什么情况?
- java - 替代字符串组合不是“+”的字符串
- mysql - 在这种情况下如何重写 COUNT 的正确语句
- javascript - 我想添加一个按钮 onclick 功能,在 javascript 中添加几个 toast
- flutter - 如何使用颤振将列表项放在底部导航中?
- android - 如何按照特殊规则以编程方式缩放和裁剪图像
- nginx - 为什么我在 EKS 中使用 ALB 入口控制器时没有创建目标?
- python - 从父类 PYTHON 继承时出错
- python - Pythons Pandas - 将列中的 Str 对象值转换为浮点数