Python 之模块fnmatch
2014-02-28 17:46
429 查看
>>> name = ['zhu','jiang','a.txt'] >>> fnmatch.filter(name,'*.txt') ['a.txt'] 相当于 >>> [n for n in name if fnmatch.fnmatch(n,'*.txt')] ['a.txt']fnmatch模块提供了支持linux风格的通配符。
fnmatch.fnmatch(filename, pattern):测试所给的文件filename是否匹配所给的模式pattern
>>> fnmatch.fnmatch('/root/zhu.txt','*.txt') True >>> fnmatch.fnmatch('/root/zhu.txt','*.txt1') Falsefnmatch.fnmatchcase(filename, pattern) :测试是否匹配模式时区分大小写,(用在操作系统不区分大小写的情况下)
>>> fnmatch.fnmatch('/root/zhu.txt','*.Txt') Falsefnmatch.filter(names, pattern) :返回一个列表的子集,等价于
[n for n in names if fnmatch(n, pattern)]
>>> name = ['zhu','jiang','a.txt'] >>> fnmatch.filter(name,'*.txt') ['a.txt'] >>> [n for n in name if fnmatch.fnmatch(n,'*.txt')] ['a.txt']
相关文章推荐
- python模块整理8-glob(类似grep)和fnmatch(匹配文件名)
- Python fnmatch 模块
- Python: fnmatch模块 (Unix B-Shell通配符的文件名匹配)
- fnmatch模块_______python模块学习1
- 使用python的logging模块
- 关于python 模块导入
- Python中导入非默认路径的模块
- Python从内存中使用编译后的模块
- Python模块学习 ---- struct 数据格式转换
- python模块学习之__future__
- Python的io模块详解
- Python datetime模块
- python下面通过ctypes模块调用c++库的方法
- python的email模块
- python脚本传入参数--精讲(getopt模块)
- python数据持久存储:pickle模块的基本使用
- Python 用于网站抓取 登录 发布的模块介绍
- Python3使用pandas模块读写excel操作示例
- 2.python语法基础-模块
- python 模块 包