fnmatch 优点在于 linux shell通配符

fnmatch模块: 优点在于提供对Unix Shell通配符的支持

Pattern Meaning 
*       matches everything 
?       matches any single character 
[seq]   matches any character in seq 
[!seq]  matches any character not in seq 

  • import fnmatch  
  1. for file in os.listdir('.'):  
  2.     if fnmatch.fnmatch(file, '*.py'):  
  3.         print file  
glob模块: 查找所有满足Unix Shell模式规则的路径名
 
  1. import os  
  2. import glob  
  3. for f in glob.glob(os.path.join(os.path.abspath('.'), '*')):  
  4.     print f 

 

猜你喜欢

转载自www.cnblogs.com/koujiaodahan/p/9022558.html