Python中os.path.join和os.path.split()和os.path.splitext()函数用法

import os

root_dir = r'pycococreatortools'
# os.path.join(root_dir, str):将root_dir,str部分合成一个整体
print("执行结果:", os.path.join(root_dir, '_os_path_'))

file_AP = 'E:\COVID-19CTimageAnal\pycococreator\os.py'
# os.path.split()返回文件的路径和文件名
dir, _filename=os.path.split(file_AP)
print("dir:", dir, "_filename:", _filename)

#os.path.splitext()将文件名和扩展名分开
filename_, suffix=os.path.splitext(_filename)
print("filename_:", filename_, "suffix:", suffix)

# 输出
执行结果: pycococreatortools\_os_path_
dir: E:\COVID-19CTimageAnal\pycococreator _filename: os.py
filename_: os suffix: .py

 

猜你喜欢

转载自www.cnblogs.com/dyc99/p/12698391.html