weiok

若不包含子目录的遍历:

 

import glob

 

for filename in glob.glob("/data/testdata/*.jpg"):

    print filename

 

 

包含子目录

 

import os

import fnmatch

 

def iterfindfiles(path, fnexp):

    for root, dirs, files in os.walk(path):

        for filename in fnmatch.filter(files, fnexp):

            yield os.path.join(root, filename)

 

for filename in iterfindfiles(r"/data/testdata", "*.jpg"):

    print filename

 

 

yield 用法讲解 http://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2022-01-07
猜你喜欢
  • 2021-11-18
  • 2021-11-18
  • 2022-12-23
  • 2021-12-15
  • 2021-05-29
  • 2022-12-23
相关资源
相似解决方案