EOF在解析包含在python图像的文件

问题描述 投票:0回答:1

我不明白为什么我会在这里得到EOF错误。有人可以帮助吗?here I am trying to iterate over a folder 'Flowers' containing 3 images which I want to display but I get EOF error no matter what

this is the error occuring

此外,当我只显示1图象的2行的代码未注释的工作原理。我想显示所有图像,我该怎么办呢?

python image eof cv2
1个回答
0
投票

理由:EOF错误是由缺少for-loop块造成的。对于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()
© www.soinside.com 2019 - 2024. All rights reserved.