python包:glob用法

来源:互联网 发布:java九大排序算法 编辑:程序博客网 时间:2024/06/07 11:00

python的glob包用法:
该包包含两个主要的函数glob和iglob,输入参数均是文件路径,返回值glob为文件列表(无序),iglob为迭代器:

glob.glob(pathname)¶Return a possibly-empty list of path names that match pathname, which must be a string containing a path specification. pathname can be either absolute (like /usr/src/Python-1.5/Makefile) or relative (like ../../Tools/*/*.gif), and can contain shell-style wildcards. Broken symlinks are included in the results (as in the shell).glob.iglob(pathname)Return an iterator which yields the same values as glob() without actually storing them all simultaneously.

例如:

import globa=glob.iglob(r'F:\my\*.pdf')for i in a:    print(i)

输出:

F:\my\HMEC_100kb_MAPGE30.pdfF:\my\HMEC_100k_MAPG0.pdfF:\my\HMEC_100k_MAPGE30.pdfF:\my\HMEC_5k_MAPG0.pdfF:\my\IMR90_100kb_MAPG0.pdfF:\my\IMR90_100k_MAPG0.pdf
原创粉丝点击