os.path
>>> import os >>> os.path.dirname('/opt/mysql/data/ibdata1') '/opt/mysql/data' >>> os.path.dirname('ibdata1') '' >>> os.path.abspath('ibdata1') '/opt/mysql/data/ibdata1' >>> os.path.dirname(os.path.abspath('ibdata1')) '/opt/mysql/data' >>> os.path.basename('/opt/mysql/data/ibdata1') 'ibdata1'
#如果传入文件是完整路径,则输出文件目录 #如果传入只是文件名,则输出none os.path.dirname #输出文件的绝对路径 os.path.abspath #输出文件名 os.path.basename