for foldername in os.listdir(mainpath):
x = 0
if foldername[-4:] != ".rar":
path = mainpath + "\\" + foldername
for i in os.listdir(path):
if i[-4:] == '.jpg' or i[-5:] == '.jpeg':
#Do something with with image found
x += 1
if x > 0:
#images found
Python在x + = 1
时一直给我一个语法错误语法没什么问题,我只是在每次找到图像时增加变量,并在主循环移动到新文件夹时将其重置为x = 0
答案 0 :(得分:1)
您可能在x += 1
之前的行上缺少右括号,在您省略的部分中:
#Do something with with image found
检查do something
的最后一行,并确保括号,括号和花括号都是平衡的。