首页 > 编程语言 > 详细

Python os.path模块

时间:2017-05-22 18:44:40      阅读:278      评论:0      收藏:0      [点我收藏+]

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模块

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!