python更改图片后缀jpg->png

import os
pathdir = r"/home/csj/task/task1/train"
for file in os.listdir(pathdir):
    ext = os.path.splitext(file)
 
    if ext[1] == '.jpg':
        newext = '.png'
        filename = ext[0] + newext
        oldfile = os.path.join(pathdir,file)
        newfile = os.path.join(pathdir,filename)
        os.rename(oldfile,newfile)
    原文作者:826560347
    原文地址: https://blog.csdn.net/qq_44501345/article/details/105828385
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞