Python开发--os.path
来源:互联网 发布:cda数据分析师相关数据 编辑:程序博客网 时间:2024/05/16 14:29
转载自http://www.cnblogs.com/hongten/p/hongten_python_os_apth.html
在python中,os.path模块在处理路径的时候非常有用
下面是我做的demo
运行效果:
=========================================
代码部分:
=========================================
#python osimport osdef abspath(path): '''Return a normalized absolutized version of the pathname path''' return os.path.abspath(path)def dirname(path): '''Return the directory name of pathname path''' return os.path.dirname(path)def getatime(path): '''Return the time of last access of path''' return os.path.getatime(path)def gettime(path): '''Return the time of last modification of path''' return os.path.gettime(path)def getsize(path): '''Return the size, in bytes, of path. Raise OSError if the file does not exist or is inaccessible.''' return os.path.getsize(path)def is_file(path): '''Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path.''' return os.path.isfile(path)def is_dir(path): '''Return True if path is an existing directory. This follows symbolic links, so both islink() and isdir() can be true for the same path.''' return os.path.isdir(path)def is_link(path): '''Return True if path refers to a directory entry that is a symbolic link. Always False if symbolic links are not supported.''' return os.path.islink(path)def splitext(path): ''' Split the pathname path into a pair (root, ext) such that root + ext == path, and ext is empty or begins with a period and contains at most one period. Leading periods on the basename are ignored; splitext('.cshrc') returns ('.cshrc', ''). ''' return os.path.splitext(path)def splitunc(path): ''' Split the pathname path into a pair (unc, rest) so that unc is the UNC mount point (such as r'\\host\mount'), if present, and rest the rest of the path (such as r'\path\file.ext'). For paths containing drive letters, unc will always be the empty string. ''' return os.path.splitunc(path)def split(path): '''Split the pathname path into a pair, (head, tail) where tail is the last pathname component and head is everything leading up to that''' return os.path.split(path) def main(): path_file = 'C:\\test.html' path_dir = 'C:\\Windows\\Branding' print(abspath(path_file)) print(dirname(path_dir)) print(getatime(path_file)) print(getsize(path_file)) print(splitext(path_file)) print(splitunc(path_file)) print(split(path_file))if __name__ == '__main__': main()
0 0
- Python开发--os.path
- Python os.path模块
- Python os.path模块
- python os.path
- [python] os.path模块
- python os.path模块
- Python os.path模块
- Python os.path模块
- python os.path模块
- Python os.path模块
- python os.path模块
- Python os.path模块
- python os.path模块
- Python os.path模块
- python os.path模块
- Python os.path模块
- python os.path
- Python os.path模块
- iOS 9之应用内搜索(CoreSpotlight)API
- EXtJS 创建一个窗体Window
- Android Framework_Android系统启动过程
- 64位CPU内存限制
- java之Unicode编码 -一段代码
- Python开发--os.path
- gcd,快速幂,邻接表问题 (深度优先搜索的三个范例)
- Python开发--bisect
- 树状数组 求逆序数
- MySQL重做日志
- 2015080405 - 书评们给点有价值的意见呗
- Python KNN 情感分类
- ListView左滑删除&代理模式
- CentOS7关闭防火