python开发_os.path
时间:2022-06-10
本文章向大家介绍python开发_os.path,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
在python中,os.path模块在处理路径的时候非常有用
下面是我做的demo
运行效果:
=========================================
代码部分:
=========================================
1 #python os
2
3 import os
4
5 def abspath(path):
6 '''Return a normalized absolutized version of the pathname path'''
7 return os.path.abspath(path)
8
9 def dirname(path):
10 '''Return the directory name of pathname path'''
11 return os.path.dirname(path)
12
13 def getatime(path):
14 '''Return the time of last access of path'''
15 return os.path.getatime(path)
16
17 def gettime(path):
18 '''Return the time of last modification of path'''
19 return os.path.gettime(path)
20
21 def getsize(path):
22 '''Return the size, in bytes, of path. Raise OSError if the file does not exist or is inaccessible.'''
23 return os.path.getsize(path)
24
25 def is_file(path):
26 '''Return True if path is an existing regular file.
27 This follows symbolic links, so both islink() and isfile()
28 can be true for the same path.'''
29 return os.path.isfile(path)
30
31 def is_dir(path):
32 '''Return True if path is an existing directory. This follows symbolic links,
33 so both islink() and isdir() can be true for the same path.'''
34 return os.path.isdir(path)
35
36 def is_link(path):
37 '''Return True if path refers to a directory entry that
38 is a symbolic link. Always False if symbolic links are not supported.'''
39 return os.path.islink(path)
40
41 def splitext(path):
42 '''
43 Split the pathname path into a pair (root, ext) such that
44 root + ext == path, and ext is empty or begins with a period
45 and contains at most one period. Leading periods on the basename
46 are ignored; splitext('.cshrc') returns ('.cshrc', '').
47 '''
48 return os.path.splitext(path)
49
50 def splitunc(path):
51 '''
52 Split the pathname path into a pair (unc, rest) so that unc is
53 the UNC mount point (such as r'\hostmount'), if present,
54 and rest the rest of the path (such as r'pathfile.ext').
55 For paths containing drive letters, unc will always be the
56 empty string.
57 '''
58 return os.path.splitunc(path)
59
60 def split(path):
61 '''Split the pathname path into a pair, (head, tail) where tail is the last
62 pathname component and head is everything leading up to that'''
63 return os.path.split(path)
64
65 def main():
66 path_file = 'C:\test.html'
67 path_dir = 'C:\Windows\Branding'
68 print(abspath(path_file))
69 print(dirname(path_dir))
70 print(getatime(path_file))
71 print(getsize(path_file))
72 print(splitext(path_file))
73 print(splitunc(path_file))
74 print(split(path_file))
75
76
77 if __name__ == '__main__':
78 main()
- PHP制作百度站内搜索绿色通道的网页列表数据文件
- 分享几个可用的二维码API,以及给博客添加文章二维码图片的方法
- AI即开即用,这是悄然推出的“腾讯最新AI技术”小程序
- Android Linker 与 SO 加壳技术
- Go语言操作mysql数据库简单例子
- go语言的sql包原理与用法分析
- WordPress免插件生成完整站点地图(sitemap.xml)的php代码
- Go语言常用字符串处理方法实例汇总
- 硬盘故障时如何强制关机:Input/output error
- 举例讲解Go语言中函数的闭包使用
- 实现WordPress提交评论的时删除该页面的WP-Super-Cache缓存的方法
- php自动生成百度开放适配PC页-手机页pattern对应关系sitemap.xml
- Linux系统最大文件打开数优化,解决Too many open files报错
- 【Dev Club 分享】安卓单元测试:What, Why and How
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- PHP46 个非常有用的代码片段
- python删除列表元素
- PHP中file_get_contents的使用方法
- PHP中的 fastcgi_finish_request();
- PHP超实用的函数总结整理
- R语言使用Rasch模型分析学生答题能力
- PHP中的const
- Python贝叶斯回归分析住房负担能力数据集
- PHP异常处理
- np.argsort函数
- PHP中this,self,parent的区别
- R语言基于协方差的SEM结构方程模型中的拟合指数
- Stata中的治疗效果:RA:回归调整、 IPW:逆概率加权、 IPWRA、 AIPW
- R语言在不同样本量下的Littles MCAR检验
- PHP10段常用功能代码