多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
此模块支持Unix shell样式通配符,不是与正则表达式(在re模块中记录)相同。shell样式通配符中使用的特殊字符是: ![](http://om4h63cja.bkt.clouddn.com/17-5-31/66804049.jpg) * fnmatch.fnmatch(filename, pattern) 测试 filename 是否匹配 pattern , 返回True或者False.。如果操作系统大小写敏感, 这两个参数在比较之前将会转化为大写或者小写。 * fnmatch.fnmatchcase(filename, pattern) 测试 filename是否匹配 pattern, 返回True 或者 False; 这个比较是**大小写敏感**的。 * fnmatch.filter(names, pattern) 返回列表names中匹配pattern. 的子项。等价于[n for n in names if fnmatch(n, pattern)], 但更加实用且高效。 * fnmatch.translate(pattern) 返回转换为一个正则表达式 shell 风格的pattern。 ~~~ >>> import fnmatch, re >>> >>> regex = fnmatch.translate('*.txt') >>> regex '.*\\.txt$' >>> reobj = re.compile(regex) >>> reobj.match('foobar.txt') <_sre.SRE_Match object at 0x...> ~~~