fnmatch模块的使用
来源:互联网 发布:网络摄像头哪个牌子好 编辑:程序博客网 时间:2024/05/21 14:48
简单记录一下fnmatch模块的使用,此模块的主要作用是文件名称的匹配,并且匹配的模式使用的unix shell风格。字面意思感觉就是filename match
如下例子所示:
#!/usr/bin/env pythonimport osimport fnmatchfor filename in os.listdir('.'): if fnmatch.fnmatch(filename,'*.txt'): #匹配模式为星号,表示任意的字符 print filename例子中,主要使用os.listdir来列出当前目录中的文件,如果匹配的后缀为.txt,那么就打印出来,fnmatch.fnmatch是一个布尔函数,返回为True或者Faulse。
主要使用的匹配模式如下:
if fnmatch.fnmatch('kel','?el'): #匹配模式为问号,及匹配一个任意字符 print 'match'if fnmatch.fnmatch('kel','[a-z]el'): #匹配模式为单个字符,在a-z之间 print 'match'if fnmatch.fnmatch('1el','[!a-z]el'):#匹配模式为不能是a-z之间的字符 print 'match'执行结果如下:
[root@python 429]# python fnmatchexample.py kel.txtmatchmatchmatch问号相当于一个占位符,从而能匹配
k是字母a-z之间的字母,从而能匹配
数字1不在a-z之间的字母,从而能匹配
0 0
- fnmatch模块的使用
- python fnmatch模块使用
- Python fnmatch 模块
- Python: fnmatch模块 (Unix B-Shell通配符的文件名匹配)
- fnmatch
- fnmatch
- fnmatch
- 美丽的fnmatch(匹配函数)
- 支持通配符的字符串比较——POSIX函数fnmatch
- php适用于windows的fnmatch(匹配函数),可匹配中文。
- fnmatch.h
- fnmatch函数
- python -- fnmatch
- python fnmatch
- CMEM模块的使用
- mc703模块的使用
- python_bisect模块的使用
- python_glob模块的使用
- eclipse设置代理
- 深入研究 Visual Studio Code for Golang
- android apk编译过程(1)
- hdu3400 _嵌套三分 三分求极限
- hdu1698 Just a Hook(成段更新+懒惰标记)
- fnmatch模块的使用
- 最大映射
- poj 3608(旋转卡壳求解两凸包之间的最短距离)
- 字典树
- hdoj1025Constructing Roads In JGShining's Kingdom【LIS】
- 我的第一个嵌入式linux驱动(基于韦东山led驱动)
- [linux]查看端口号占用情况
- IOS学习 绘图 UIBezierPath 绘基本图形、样式设置、渲染填充
- 运算器的特殊实现方法