os.path.join (python路径拼接)

os.path.join (python路径拼接),第1张

os.path.join (python路径拼接) python路径拼接os.path.join()函数的用法
# 数据路径
    root = 'H:Butterfly_detectionyolov5-1.0-baselineVOCdevkitVOC2007'
    img_dir = root + '/JPEGImages'
    anno_path = root + '/Annotations'
    imgs_path = GetFileFromThisRootDir(img_dir)  # 返回每一张原图的路径
    AUG = 'Flip'  # 数据扩增的方式 Rotate代表旋转,Flip表示翻转

    # 存储新的anno位置
    anno_new_dir = os.path.join(root, AUG, 'xml')  #所以保存的路径为:H:Butterfly_detectionyolov5-1.0-baselineVOCdevkitVOC2007AUG
    if not os.path.isdir(anno_new_dir):
        os.makedirs(anno_new_dir)
    # 扩增后图片保存的位置
    img_new_dir = os.path.join(root, AUG, 'images')
    if not os.path.isdir(img_new_dir):
        os.makedirs(img_new_dir)
具体例子
import os

Path1 = 'home'
Path2 = 'develop'
Path3 = 'code'

Path10 = Path1 + Path2 + Path3
Path20 = os.path.join(Path1,Path2,Path3)
print ('Path10 = ',Path10)
print ('Path20 = ',Path20)

#输出:

#Path10 = homedevelopcode
#Path20 = homedevelopcode

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4696242.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-07
下一篇 2022-11-07

发表评论

登录后才能评论

评论列表(0条)

保存