本文實(shí)例講述了Python挑選文件夾里寬大于300圖片的方法。分享給大家供大家參考。具體分析如下:
這段代碼需要用到PIL庫。代碼如下所示:
import sysimport ossys.path.append('PIL')from PIL import Image as impath = '/home/hualun/桌面/img/'new_path = '/home/hualun/桌面/img2/'for x in os.listdir(path): if x.endswith('.jpg'): file = im.open(path+x) width = file.size[0] if width > 300: os.rename(path+x, new_path+x) print "%s 移動(dòng)完成.." % x希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選