从一个路径到目的文件的相对路径
import os
os.path.relpath(__file__, start='/Users/Jason/Desktop/CV/')
../../Documents/Projects/DataMining/ml.py
用户的根目录
os.path.expanduser('~')
/Users/Jason
获取文件的目录路径
os.path.dirname(os.path.realpath(__file__))
/Users/Jason/Documents/Projects/DataMining
区分文件的目录与文件名
os.path.split(os.path.realpath(__file__))
('/Users/Jason/Documents/Projects/DataMining', 'ml.py')
文件的绝对路径
os.path.abspath(__file__)
/Users/Jason/Documents/Projects/DataMining/ml.py
路径字符串的连接
os.path.join('/rootpath', 'dirname1', 'dirname2', 'filename')
/rootpath/dirname1/dirname2/filename