问题描述
我遵循了一个包含以下Python代码的教程,以查找损坏的jpg文件。我有一个经过测试的jpg损坏图像,脚本找不到该文件。有什么我想念的吗?运行Python 3.9。
编辑:对不起,我忘了说。我确实在自己的脚本中将“ if endswith”更改为“ .jpg”。这只是教程中的复制面食。
from os import listdir
from PIL import Image
for filename in listdir('./'):
if filename.endswith('.png'):`
try:
img = Image.open('./'+filename) # open the image file
img.verify() # verify that it is,in fact an image
except (IOError,SyntaxError) as e:
print('Bad file:',filename) # print out the names of corrupt files
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)