python glob model
来源:互联网 发布:知乎北理工足球 编辑:程序博客网 时间:2024/06/03 08:24
python glob model
说明:
1、glob是python自己带的一个文件操作相关模块,用它可以查找符合自己目的的文件,就类似于Windows下的文件搜索,支持通配符操作,*,?,[]这三个通配符,*代表0个或多个字符,?代表一个字符,[]匹配指定范围内的字符,如[0-9]匹配数字。
它的主要方法就是glob,该方法返回所有匹配的文件路径列表,该方法需要一个参数用来指定匹配的路径字符串(本字符串可以为绝对路径也可以为相对路径),其返回的文件名只包括当前目录里的文件名,不包括子文件夹里的文件。
比如:
glob.glob(r'c:\*.txt')
我这里就是获得C盘下的所有txt文件
glob.glob(r'E:\pic\*\*.jpg')
获得指定目录下的所有jpg文件
使用相对路径:
glob.glob(r'../*.py')
2、iglob方法:
获取一个可编历对象,使用它可以逐个获取匹配的文件路径名。与glob.glob()的区别是:glob.glob同时获取所有的匹配路径,而 glob.iglob一次只获取一个匹配路径。这有点类似于.NET中操作数据库用到的DataSet与DataReader。下面是一个简单的例子:
#父目录中的.py文件
f = glob.iglob(r'../*.py')
print f #<generator object iglob at 0x00B9FF80>
for py in f:
- 官方说明:
- 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 http://www.cnblogs.com/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.
New in version 2.5.
For example, consider a directory containing only the following files: 1.gif, 2.txt, andcard.gif. glob() will produce the following results. Notice how any leading components of the path are preserved.
- python glob model
- python glob model
- python glob.glob使用
- python之glob模块
- [python] glob模块
- python glob模块
- python glob模块
- python glob模块
- Python linecache、glob模块
- Python:glob模板
- python glob模块
- Python开发--glob
- python glob模块
- Python: glob匹配文件
- python模块glob
- python glob使用
- python中的glob包
- Python glob使用
- Redhat Linux 9.0 在vmware下,不能上网的解决方法
- Java系统程序员修炼之道
- Java系统程序员修炼之道
- Skype for iPhone 来电后台唤醒原理 &2010 Apple iPhone 4.0 OS 发布会
- 对于CDHtmlDialog和JavaScript、HTML配合使用的一些技术总结
- python glob model
- wiresharkIP过滤:包括来源IP或者目标IP等于某个IP比如
- Google Maps JavaScript API V3的使用(一)
- 使用JS合并单元格
- Linux下三国杀聊天窗口乱码 解决方法
- struts2平台搭建
- 如何在 IOP 期刊上发表论文
- Eclipse获取工作空间路径
- EasyMock 使用方法与原理剖析