Python中os.path用法分析


Posted in Python onJanuary 15, 2015

本文实例分析了Python中os.path用法。分享给大家供大家参考。具体如下:

#coding=utf-8

import os

print os.path.abspath("d:\\new\\test.txt")

print os.path.basename("d:\\new\\test.txt")

print os.path.dirname("d:\\new\\test.txt")

print os.path.exists("d:\\new")

print os.path.lexists("d:\\new")

print os.path.expanduser("d:\\new\\text.txt")

print os.path.getatime("d:\\new")  #最后访问时间

print os.path.getmtime("d:\\new") #最后修改路径时间

print os.path.getctime("d:\\new")  #创建时间

print os.path.getsize("d:\\new\\")  #或许路径的大小 字节为单位

print os.path.isabs("d:\\")  #是否是绝对路径

print os.path.isfile("d:\\new\\hello.txt")

print os.path.isdir("d:\\new")

print os.path.islink("d:\\new\\hello.txt")

print os.path.join("d:\\new","hello.txt")

print os.path.normcase("d:\\new\\hello.txt")

print os.path.relpath("d:\\new\\hello.txt")  #相对路径

print os.path.split("d:\\new\\hello.txt")  #分离文件名

print os.path.splitdrive("d:\\new\\hello.txt")  #分离磁盘驱动器

print os.path.splitext("d:\\new\\hello.txt")  #分离扩展名

运行结果:
>>>
d:\new\test.txt
test.txt
d:\new
True
True
d:\new\text.txt
1322235096.47
1322235096.47
1321610018.9
16384
True
True
True
False
d:\new\hello.txt
d:\new\hello.txt
hello.txt
('d:\\new', 'hello.txt')
('d:', '\\new\\hello.txt')
('d:\\new\\hello', '.txt')
>>>

希望本文所述对大家的Python程序设计有所帮助。

Python 相关文章推荐
Python struct.unpack
Sep 06 Python
python进阶教程之文本文件的读取和写入
Aug 29 Python
Python实现数通设备端口使用情况监控实例
Jul 15 Python
详解Python字符串对象的实现
Dec 24 Python
Python 实现一个颜色色值转换的小工具
Dec 06 Python
Pandas DataFrame 取一行数据会得到Series的方法
Nov 10 Python
十分钟搞定pandas(入门教程)
Jun 21 Python
基于Python+Appium实现京东双十一自动领金币功能
Oct 31 Python
pytorch 常用线性函数详解
Jan 15 Python
python 子类调用父类的构造函数实例
Mar 12 Python
给keras层命名,并提取中间层输出值,保存到文档的实例
May 23 Python
python实现暗通道去雾算法的示例
Sep 27 Python
python静态方法实例
Jan 14 #Python
python继承和抽象类的实现方法
Jan 14 #Python
python列表操作实例
Jan 14 #Python
python操作gmail实例
Jan 14 #Python
Python中的装饰器用法详解
Jan 14 #Python
python登陆asp网站页面的实现代码
Jan 14 #Python
Python的面向对象思想分析
Jan 14 #Python
You might like
163的邮件用phpmailer发送(实例详解)
2013/06/24 PHP
PHP实现简单的新闻发布系统实例
2015/07/28 PHP
学习PHP的数组总结【经验】
2016/05/05 PHP
php传值方式和ajax的验证功能
2017/03/27 PHP
基于PHP+Jquery制作的可编辑的表格的代码
2011/04/10 Javascript
javascript学习笔记(一) 在html中使用javascript
2012/06/18 Javascript
JS异常处理的一个想法(sofish)
2013/03/14 Javascript
解析dom中的children对象数组元素firstChild,lastChild的使用
2013/07/10 Javascript
js 限制input只能输入数字、字母和汉字等等
2013/12/18 Javascript
IE6下javasc#ipt:void(0) 无效的解决方法
2013/12/23 Javascript
js实现网页随机切换背景图片的方法
2014/11/01 Javascript
动态加载js的方法汇总
2015/02/13 Javascript
剖析Node.js异步编程中的回调与代码设计模式
2016/02/16 Javascript
JavaScript Date对象详解
2016/03/01 Javascript
jQuery插件datatables使用教程
2016/04/21 Javascript
Vue2.0组件间数据传递示例
2017/03/07 Javascript
jQuery制作input提示内容(兼容IE8以上)
2017/07/05 jQuery
基于vue-ssr服务端渲染入门详解
2018/01/08 Javascript
微信小程序批量监听输入框对按钮样式进行控制的实现代码
2019/10/12 Javascript
easyUI 实现的后台分页与前台显示功能示例
2020/06/01 Javascript
[38:30]2014 DOTA2国际邀请赛中国区预选赛 LGD-GAMING VS CIS 第一场2
2014/05/24 DOTA
[48:56]2018DOTA2亚洲邀请赛 3.31 小组赛 A组 VG vs KG
2018/03/31 DOTA
Python语言实现百度语音识别API的使用实例
2017/12/13 Python
python实现一个简单的ping工具方法
2019/01/31 Python
Python使用pyserial进行串口通信的实例
2019/07/02 Python
Django CSRF跨站请求伪造防护过程解析
2019/07/31 Python
scrapy-splash简单使用详解
2021/02/21 Python
Web Service面试题:如何搭建Axis2的开发环境
2012/06/20 面试题
管理心得体会
2013/12/28 职场文书
中学生个人自我评价
2014/02/06 职场文书
企业元宵节主持词
2014/03/25 职场文书
委托书格式
2014/08/01 职场文书
合作合同协议书范本
2015/01/27 职场文书
2016年小学生新年寄语
2015/08/18 职场文书
自制短波长线天线频率预选器 - 成功消除B2K之流的镜像
2021/04/22 无线电
Go 实现英尺和米的简单单位换算方式
2021/04/29 Golang