我不明白为什么我会在这里得到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
此外,当我只显示1图象的2行的代码未注释的工作原理。我想显示所有图像,我该怎么办呢?
理由: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()