python之os.path的用法
一、os.path常用函数介绍介绍
import os
os.path.dirname(filename)
os.path.abspath(filename)
os.path.join()
os.path.splitext(file)
os.path.normpath(catalog)
os.path.exists(filecatalog)
os.path.split(file or catalog)
os.path.join(os.getcwd(),'aaa', ‘bbb’, ‘ccc’)
二、案例以及结果
2.1 案例
import os
path1 = os.path.dirname('test.py')
print(path1)
path2 = os.path.abspath('test.py')
print(path2)
path3 = os.path.join(os.path.dirname(os.path.abspath('test.py')), 'test1.py')
print(path3)
2.2 执行结果
![在这里插入图片描述](https://img-blog.csdnimg.cn/6e3ca89402ce4f25aef8d601c8d93972.png)
三、其他os常用函数介绍
os.getcwd()
os.listdir(filecatalog)
os. chdir(filecatalog)
os.mkdir(filecatalog)
os.remove(filename)
os.linesep
os.removedirs(filename)