fnmatch模块的作用
主要用于文件名的匹配,匹配到返回True或匹配不到返回False。
1、匹配文件名,是否一样
import fnmatch import os pattern = 'server_*.py' print('Pattern:', pattern) files = os.listdir('.') for name in sorted(files): print('文件名: {:<25} {}'.format(name, fnmatch.fnmatch(name, pattern)))