glob模块
主要是用来在匹配文件,相当shell中用通配符匹配.
用法:
glob.glob(pathname) # 返回匹配的文件作为一个列表返回
glob.iglob(pathname) # 匹配到的文件名,返回一个迭代器
ps: pathname是路径, 可以是绝对和相对路径
匹配当前目录下有一个数字开头的文件
>>> import glob
>>> glob.glob('./[0-9].*')
['./1.gif', './2.txt']
>>> glob.glob('*.gif')
['1.gif', 'card.gif']
>>> glob.glob('?.gif')
['1.gif']
匹配当前目录下所有.txt后缀的文件
>>> glob.glob('*.txt')
['172.txt', '102.txt', '185.txt', '165.txt', '11.txt', '51.txt', '91.txt', '113.txt', '78.txt', '198.txt', '35.txt', '82.txt', '171.txt', '173.txt', '97.txt', '57.txt', '37.txt', '150.txt', '42.txt', '23.txt', '25.txt', '160.txt', '143.txt', '29.txt', '149.txt', '176.txt', '191.txt', '105.txt', '86.txt', '30.txt', '120.txt', '133.txt', '68.txt', '77.txt', '41.txt', '31.txt', '152.txt', '117.txt', '175.txt', '3.txt', '159.txt', '44.txt', '19.txt', '178.txt', '200.txt', '2.txt', '112.txt', '34.txt', '17.txt', '65.txt', '183.txt', '119.txt', '18.txt', '70.txt', '40.txt', '135.txt', '89.txt', '114.txt', '184.txt', '154.txt', '61.txt', '115.txt', '94.txt', '32.txt', '92.txt', '116.txt', '5.txt', '158.txt', '157.txt', '69.txt', '137.txt', '45.txt', '111.txt', '81.txt', '15.txt', '103.txt', '10.txt', '104.txt', '95.txt', '190.txt', '145.txt', '126.txt', '96.txt', '46.txt', '122.txt', '118.txt', '84.txt', '85.txt', '195.txt', '99.txt', '79.txt', '39.txt', '64.txt', '26.txt', '197.txt', '146.txt', '163.txt', '194.txt', '179.txt', '134.txt', '7.txt', '129.txt', '189.txt', '4.txt', '170.txt', '107.txt', '155.txt', '16.txt', '109.txt', '93.txt', '121.txt', '72.txt', '56.txt', '55.txt', '67.txt', '196.txt', '177.txt', '167.txt', '192.txt', '182.txt', '80.txt', '62.txt', '186.txt', '151.txt', '169.txt', '48.txt', '147.txt', '83.txt', '74.txt', '21.txt', '124.txt', '88.txt', '142.txt', '174.txt', '139.txt', '87.txt', '128.txt', '71.txt', '53.txt', '63.txt', '156.txt', '59.txt', '1.txt', '33.txt', '108.txt', '49.txt', '75.txt', '141.txt', '136.txt', '164.txt', '131.txt', '180.txt', '38.txt', '14.txt', '28.txt', '130.txt', '22.txt', '43.txt', '168.txt', '8.txt', '144.txt', '54.txt', '12.txt', '9.txt', '187.txt', '125.txt', '166.txt', '188.txt', '199.txt', '138.txt', '181.txt', '101.txt', '27.txt', '13.txt', '36.txt', '162.txt', '153.txt', '58.txt', '50.txt', '148.txt', '47.txt', '132.txt', '140.txt', '127.txt', '90.txt', '6.txt', '100.txt', '66.txt', '193.txt', '123.txt', '98.txt', '106.txt', '52.txt', '24.txt', '76.txt', '20.txt', '60.txt', '161.txt', '73.txt', '110.txt']
glob模块相当于linux下面的通配符功能,可以用来匹配文件,不能匹配文件中的内容。
glob模块的更多相关文章
- node - glob模块
node的glob模块允许你使用 *等符号, 来写一个glob规则,像在shell里一样,获取匹配对应规则的文件. 这个glob工具基于javascript.它使用了 minimatch 库来进行匹配 ...
- devi into python 笔记(五)异常 文件操作 sys os glob模块简单实用
异常: Java异常: try catch块处理异常,throw引发异常. Python异常: try except块处理异常,raise引发异常. 异常如果不主动处理,则会交给Python中的缺省处 ...
- 【python】python中 简单的 glob模块
glob模块是最简单的模块之一,内容非常少.用它可以查找符合特定规则的文件路径名.跟使用windows下的文件搜索差不多.查找文件只用到三个匹配符:"*", "?&quo ...
- Python第十一天 异常处理 glob模块和shlex模块 打开外部程序和subprocess模块 subprocess类 Pipe管道 operator模块 sorted函数 os模块 hashlib模块 platform模块 csv模块
Python第十一天 异常处理 glob模块和shlex模块 打开外部程序和subprocess模块 subprocess类 Pipe管道 operator模块 sorted函 ...
- python glob模块使用笔记(更新)
glob模块是通配用的,用于列出符合通配格式的文件 glob.glob(path) path是用于匹配的字符串,类似简单版的正则吧 其中 * 匹配任意多个字符 ? 匹配一个字符 [1-9] 匹配指定范 ...
- node中glob模块
glob glob允许使用规则,从而获取对应规则匹配的文件 node的glob模块允许你使用 * 等符号,来写一个glob规则,像在shell里一样,获取匹配对应规则文件 安装 npm install ...
- python glob 模块
glob模块用来查找文件目录和文件,可以和常用的find功能进行类比.glob支持*?[]这三种通配符.返回的数据类型是list.常见的两个方法有glob.glob()和glob.iglob(),ig ...
- Python学习-33.Python中glob模块的一些参数
glob模块中有一个叫glob的方法可以获取某个目录下的文件. import glob temp=glob.glob("E:\\Temp\\*.txt") print(temp) ...
- glob 模块
# -*- coding: utf-8 -*- #python 27 #xiaodeng #glob 模块 #http://python.jobbole.com/81552/ #查找文件只用到三个匹配 ...
随机推荐
- hadoop入门(3)——hadoop2.0理论基础:安装部署方法
一.hadoop2.0安装部署流程 1.自动安装部署:Ambari.Minos(小米).Cloudera Manager(收费) 2.使用RPM包安装部署:Apache ...
- [译]:Orchard入门——给网站添加新博客
原文链接:Adding a Blog to Your Site 文章内容基于Orchard 1.8版本 Orchard提供一个博客引擎--这让添加一个新博客到你网站变得非常容易. 本文将介绍怎样添加一 ...
- 你不知道的parseInt
首先,请允许我抄袭一段你知道的parseInt 以下节选自parseInt - JavaScript | MDN 实际上你连这些基础都没掌握 概述 parseInt() 函数将给定的字符串以指 ...
- 图像分割算法-GraphSeg算法
图像分割是图像处理中的一个基础课题范围,本文简要介绍一种比较好的图像分割算法: Efficient Graph-Based Image Segmentation 论文出处:http://cs.brow ...
- Tomcat中JVM内存溢出及合理配置及maxThreads如何配置(转)
来源:http://www.tot.name/html/20150530/20150530102930.htm Tomcat本身不能直接在计算机上运行,需要依赖于硬件基础之上的操作系统和一个Java虚 ...
- [leetcode] 47. Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- PropertyMetadata和UIPropertyMetadata的一点区别
使用UIPropertyMetadata写一个Brush的依赖属性. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Act ...
- 开机自动启动Tomcat
一.安装JDK和Tomcat 1,安装JDK:直接运行jdk-7-windows-i586.exe可执行程序,默认安装即可. 备注:路径可以其他盘符,不建议路径包含中文名及特殊符号. 2.安装Tomc ...
- Git Merge Commit忘了选分支?数据丢失? 刚刚做的都丢失了?别急!
1.打开终端,进入到对应的git 目录,也就是你的项目目录. 2.然后输入 git reflog,找到自己commit的版本 3.根据对应的编码输入指令,如:git checkout e53fa44( ...
- 【BZOJ1087】 [SCOI2005]互不侵犯King 状压DP
经典状压DP. f[i][j][k]=sum(f[i-1][j-cnt[k]][k]); cnt[i]放置情况为i时的国王数量 前I行放置情况为k时国王数量为J #include <iostre ...