码迷,mamicode.com
首页 > 编程语言 > 详细

Python os.path模块

时间:2017-05-22 19:02:32      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:path   text   ext   bio   文件   扩展   路径   itext   回文   

1、os.path.splitext(path)  #返回一个元祖(路经,扩展名)

例如:

>>> os.path.splitext(‘/home/biotrainee/first/test.txt‘)
(‘/home/biotrainee/first/test‘, ‘.txt‘)

而os.path.split(path) 是返回(路经,文件名.扩张名)

>>> os.path.split(‘/home/biotrainee/first/test.txt‘)
(‘/home/biotrainee/first‘, ‘test.txt‘)

 

2、os.path.dirname(path) 返回文件路经的目录,也就是os.path.split(path)第一个元素,如:

>>> os.path.dirname(‘/home/biotrainee/first/test.txt‘)
‘/home/biotrainee/first‘

 

3、os.path.basename(path)返回path的最后文件名,也就是os.path.split(path)第二个元素,如:

>>> os.path.basename(‘/home/biotrainee/first/test.txt‘)
‘test.txt‘

 

4、os.path.exists(path)   如果path存在,返回True;如果path不存在,返回False。如:

>>> os.path.exists(‘/home/biotrainee/first/test.txt‘)
False
>>> os.path.exists(‘/home/‘)
True

 

5、os.path.isabs(path)   如果path是绝对路径,返回True。如:

>>> os.path.isabs(‘/home/biotrainee/first/test.txt‘)
True
>>> os.path.isabs(‘../biotrainee/first/test.txt‘)
False

 

等等等等,未完待续。。。

 

Python os.path模块

标签:path   text   ext   bio   文件   扩展   路径   itext   回文   

原文地址:http://www.cnblogs.com/nklzj/p/6890725.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!