fnmatch 模块使用模式来匹配文件名
>>> from fnmatch import fnmatch, fnmatchcase
>>> fnmatch('foo.txt', '*.txt')
True
>>> fnmatch('foo.txt', '?oo.txt')
True
>>> fnmatch('Dat45.csv', 'Dat[0-9]*')
True
>>> names = ['Dat1.csv', 'Dat2.csv', 'config.ini', 'foo.py']
>>> [name for name in names if fnmatch(name, 'Dat*.csv')]
['Dat1.csv', 'Dat2.csv']
>>>
addresses = [
{'address':'5412 N CLARK', 'date': '07/01/2012'},
{'address':'5148 N CLARK', 'date': '07/04/2012'},
{'address':'5800 E 58TH', 'date': '07/02/2012'},
{'address':'2122 N CLARK', 'date': '07/03/2012'},
{'address':'5645 N RAVENSWOOD', 'date': '07/02/2012'},
{'address':'1060 W ADDISON', 'date': '07/02/2012'},
{'address':'4801 N BROADWAY', 'date': '07/01/2012'},
{'address':'1039 W GRANVILLE', 'date': '07/04/2012'},
]
>>> from fnmatch import fnmatchcase
>>> [addr for addr in addresses if fnmatchcase(addr, '* ST')]
['5412 N CLARK ST', '1060 W ADDISON ST', '2122 N CLARK ST']
>>> [addr for addr in addresses if fnmatchcase(addr, '54[0-9][0-9] *CLARK*')]
['5412 N CLARK ST']
>>>