python中os.path常用模塊
os.path.sep:路徑分隔符 linux下就用這個了’/’
os.path.altsep: 根目錄
os.path.curdir:當前目錄
os.path.pardir:父目錄
os.path.abspath(path):絕對路徑
os.path.join(): 常用來鏈接路徑
os.path.split(path): 把path分為目錄和文件兩個部分,以列表返回
1 >>> import os 2 >>> help('os.path.sep') 3 4 >>> print os.path.sep #win和linux下的不一樣,如果腳本在win下開發,在linux下面跑,可以這個,避免報錯 5 / 6 >>> print os.path.altsep 7 None 8 >>> print os.path.curdir 9 . 10 >>> print os.path.abspath('/root') 11 /root 12 >>> print os.path.abspath('/root/pp') 13 /root/pp 14 >>> print os.path.abspath('/root/pp/f.c') 15 /root/pp/f.c 16 >>> print os.path.split('/root/pp/f.c') 17 ('/root/pp', 'f.c')