《Python Cookbook》读书笔记
2.3 Matching Strings Using Shell Wildcard Patterns from fmatch import fnmatch, fnmatchcase #coding=utf-8 ''' Matching Strings Using Shell Wildcard Patterns: from fmatch import fnmatch, fnmatchcase ''' from fnmatch import fnmatch, fnmatchcase a = fnmatch('too.txt', '*.txt') b = fnmatch('foo.txt', '?oo.txt') c = fnmatch('Dat45.csv', 'Dat[0-9]*') print(a) print(b) print(c) names = ['Dat1.csv', 'Dat2.csv', 'config.ini', 'foo.py'] # 选以Dat开头的csv文件 d = [name for name in names if fnmatch(name, 'Dat*.csv')] print(d) # fnmatch是否区分大小写 与 本机操作系统一致 e = fnmatch('foo.txt', '*.TXT') print(e) f = fnmatchcase(