Python3指定路径寻找符合匹配模式文件

yipeiwu_com7年前Python基础

本文实例讲述了Python3指定路径寻找符合匹配模式文件。分享给大家供大家参考。具体实现方法如下:

这里给定一个搜索路径,需要在此目录中找出所有符合匹配模式的文件

import glob, os 
def all_files(pattern, search_path, pathsep = os.pathsep): 
  for path in search_path.split(pathsep): 
    for match in glob.glob(os.path.join(path, pattern)): 
      yield match 
print(type(all_files('*.s', 'd:\\pm\\pm')))      
print(all_files('*.s', 'd:\\pm\\pm').__next__()) 
for match in all_files('*.s', 'd:\\pm\\pm'):   
  print(match)

希望本文所述对大家的Python3程序设计有所帮助。

相关文章

Python 类,property属性(简化属性的操作),@property,property()用法示例

本文实例讲述了Python 类,property属性(简化属性的操作),@property,property()用法。分享给大家供大家参考,具体如下: property属性的创建方式有两...

浅析python 中__name__ = '__main__' 的作用

很多新手刚开始学习python的时候经常会看到python 中__name__ = \'__main__\' 这样的代码,可能很多新手一开始学习的时候都比较疑惑,python 中__na...

python 串口读取+存储+输出处理实例

研究了一晚上的成果。 import serial import win32com.client import matplotlib.pyplot as plt import...

Python获取基金网站网页内容、使用BeautifulSoup库分析html操作示例

本文实例讲述了Python获取基金网站网页内容、使用BeautifulSoup库分析html操作。分享给大家供大家参考,具体如下: 利用 urllib包 获取网页内容 #引入包 fr...

python使用scrapy发送post请求的坑

使用requests发送post请求 先来看看使用requests来发送post请求是多少好用,发送请求 Requests 简便的 API 意味着所有 HTTP 请求类型都是显而易见的...