python库的学习系列之 10. File and Directory Access
2011-01-22 13:27
471 查看
10.1. os.path — Common pathname manipulations
os.path.abspath(path) 找到path(以当前位置为准的相对位置)代表的文件的绝对路径。>>> print os.path.abspath('t') C:\Python26\t >>> print os.path.normpath(os.getcwd() + '\\t') C:\Python26\t
os.path.basename(path)
提供系统中路径操作相关的函数,很常用的、文件路径、路径归一化、判断路径是文件夹还是文件,以及获取文件大小,文件更改,创建时间等等很多接口,有一个walk函数与os.walk差不多使用。
10.2. fileinput — Iterate over lines from multiple input
streams
一次处理多个文件,让代码少点,看起来更加优雅。10.3. stat — Interpreting stat() results
文件,文件夹等等的属性判断。Stat()10.4. statvfs — Constants used with os.statvfs()
与10.3差不多的作用。10.5. filecmp — File and Directory Comparisons
文件与文件夹之间的比较。10.6. tempfile — Generate temporary files and directories
临时文件和文件夹,在进程结束后会自动回收。10.7. glob — Unix style
pathname pattern expansion
在某一目录下找与之匹配的文件,作用好比os.listdir()and fnmatch.fnmatch()联合使用的效果。
前者遍历dir下的文件,后者按照格式过滤出符合的文件。
10.8. fnmatch — Unix filename pattern matching
文件名的过滤模式。10.9. linecache — Random access to text lines
从任何一个文件中读取指定行到cache中。10.10. shutil — High-level file operations
这个是处理文件的高级用法,实现了shell中的cp,mv,rm等,以及cp -r等操作,还有打包tar,gz等等的函数make_archive等等。
10.11. dircache — Cached directory listings
这个和10.9的linecache一样,只不过这是针对dircache。相关文章推荐
- python文件和目录访问File and Directory Access
- Python_API_File and Directory Access_os.path.join
- python文件和文件夹訪问File and Directory Access
- Python_API_File and Directory Access_os.path.split
- Python_API_File and Directory Access_os.path.splitext
- Python_API_File and Directory Access_glob.glob
- Python_API_File and Directory Access_os.path.expanduser
- Python_API_File and Directory Access_os.path.normcase
- Python学习系列之Object and Object-Orientation
- Python Twisted 学习系列10(转载stulife最棒的Twisted入门教程)
- python学习笔记10:Access数据库转换为SQLite数据库之前的准备
- LINUX下c/c++的学习(4)--linux file and direction(stat fstat lstat access umask chmod ...)
- python库的学习系列之 13.2. ConfigParser — Configuration file parser
- Python 学习系列(2)and、or用法
- CUDA系列学习(二)CUDA memory & variables - different memory and variable types
- TensorFlow学习——CIFAR-10(python实现数据可视化)
- Python webdriver 读取本地csv文件中数据 提示:IOError: [Errno 2] No such file or directory
- CopyFile and Directory By channel
- Python学习系列(七)( 数据库编程)
- Python 学习File、os模块操作文件