您的位置:首页 > 编程语言 > Python开发

python_glob模块的使用

2014-05-25 15:24 399 查看
转载:http://www.verydemo.com/demo_c122_i15114.html

glob是python自己带的一个文件操作相关模块,用它可以查找符合自己目的的文件,就类似于Windows下的文件搜索,支持通配符操作,*,?,[]这三个通配符,*代表0个或多个字符,?代表一个字符,[]匹配指定范围内的字符,如[0-9]匹配数字。

它的主要方法就是glob,该方法返回所有匹配的文件路径列表,该方法需要一个参数用来指定匹配的路径字符串(本字符串可以为绝对路径也可以为相对路径),。

python手机中的介绍:

The module finds all the pathnames matching a specified pattern according to the rules used by the Unix shell. No tilde expansion is done, but,
, and character ranges expressed with
will be correctly matched. This is done by using the and functions in concert, and not by actually invoking a subshell. (For tilde and shell variable expansion, use
and.)
glob.glob(pathname) #返回列表Return a possibly-emptyof path names that matchpathname, which must be a string containing a path specification.
pathname can be either absolute (like) or relative (like), and can contain shell-style wildcards.…………………………………………………………………………
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: