os.path.join (python路径拼接)
生活随笔
收集整理的這篇文章主要介紹了
os.path.join (python路径拼接)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
python路徑拼接os.path.join()函數的用法
# 數據路徑root = 'H:\Butterfly_detection\yolov5-1.0-baseline\VOCdevkit\VOC2007'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_detection\yolov5-1.0-baseline\VOCdevkit\VOC2007\AUGif 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 osPath1 = '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 = home\develop\code總結
以上是生活随笔為你收集整理的os.path.join (python路径拼接)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 寻找波形中的极大值
- 下一篇: Python将AVI视频抽帧成图片保存