要实现的fnmatch分支**
pywildcard的Python项目详细描述
通配符
这个库是fnmatch的分支 (https://docs.python.org/2/library/fnmatch.html)来实现**
所有文档都与fnmatch相同,除了*,*现在是 **和*只影响特定目录
https://docs.python.org/2/library/fnmatch.html
示例
importpywildcarddirs=['hello/world.py','hello/world.pyc','hello/world/other/folder/example.py']pywildcard.filter(dirs,'hello/*')# ['hello/world.py', 'hello/world.pyc']pywildcard.filter(dirs,'hello/*.py')# ['hello/world.py']pywildcard.filter(dirs,'hello/**')# ['hello/world.py', 'hello/world.pyc', 'hello/world/other/folder/example.py']pywildcard.filter(dirs,'hello/**.py')# ['hello/world.py', 'hello/world/other/folder/example.py']
区分fnmatch&pywildcard
fnmatch
importreimportfnmatchurls=['example/l1/l2/test3-1.py','example/l1/test2-1.py','example/l1/test2-2.py','example/l1/l2/l3/test4-1.py']regex=fnmatch.translate('example/*')# 'example\\/.*\\Z(?ms)'re.findall(regex,"\n".join(urls))# return ['example/l1/l2/test3-1.py\nexample/l1/test2-1.py\nexample/l1/test2-2.py\nexample/l1/l2/l3/test4-1.py']
通配符
importreimportpywildcardurls=['example/l1/l2/test3-1.py','example/l1/test2-1.py','example/l1/test2-2.py','example/l1/l2/l3/test4-1.py']regex=pywildcard.translate('example/**')# 'example/.*?$(?ms)'re.findall(regex,"\n".join(urls))# return ['example/l1/l2/test3-1.py',# 'example/l1/test2-1.py',# 'example/l1/test2-2.py',# 'example/l1/l2/l3/test4-1.py']
运行单元测试
``` bash查看git存储库。Git克隆 git@github.com:agalera/python-wildcard.git输入目录。光盘 python通配符如果尚未安装pytest,请安装pytest。皮普 安装pytest运行测试pytest
更改日志
1.0.8(2015-11-26)
- 更新readme.md
1.0.7(2015-11-25)
- 添加文档