python保存图片或txt到另一个文件夹

from PIL import Image
import os

‘‘‘
保存图片到另一个文件夹
’’’
# 保存图片到test_result文件夹下,文件名字为hello.jpg
test_result_path = "./img/test_result"
image_path = "./VOCdevkit/VOC2007_test/JPEGImages/"
image = Image.open(image_path)
img_name = 'hello'
image.save(os.path.join(test_result_path, img_name + ".jpg"))


‘‘‘
保存txt到另一个文件夹
’’’
# 保存txt到dr_txt文件夹下,文件名字为hello.txt
detect_result_path = "./MAP/dr_txt"
txt_name = 'hello'
f = open(os.path.join(detect_result_path, txt_name + '.txt'), "w")
list = [1,2,3,4,5]
f.write("%s\n" % (list))
f.close()




    原文作者:Julyers
    原文地址: https://blog.csdn.net/weixin_41631106/article/details/117365685
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞