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)))
fnmatch_fnmatch.py

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2021-06-09
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-31
  • 2022-02-25
  • 2021-07-19
  • 2022-12-23
  • 2021-12-06
相关资源
相似解决方案