栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python中os.path用法分析

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python中os.path用法分析

本文实例分析了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:newtest.txt
test.txt
d:new
True
True
d:newtext.txt
1322235096.47
1322235096.47
1321610018.9
16384
True
True
True
False
d:newhello.txt
d:newhello.txt
hello.txt
('d:\new', 'hello.txt')
('d:', '\new\hello.txt')
('d:\new\hello', '.txt')
>>>

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/35794.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号