Python中实现从目录中过滤出指定文件类型的文件

yipeiwu_com6年前Python基础

最近学习下python,将从指定目录中过滤出指定文件类型的文件输出的方法总结一下,供日后查阅

复制代码 代码如下:

#!/usr/bin/env python

import glob
import os
os.chdir(“./”)
for file in glob.glob(“*.py”):
print file

print “#######Another One##########”

for file in os.listdir(“./”):
if file.endswith(“.py”):
print file

print “#######Another Two##########”
for root, dirs, files in os.walk(“./”):
for file in files:
if file.endswith(“.py”):
print os.path.join(root, file)

print “#######Another Three##########”

os.chdir(“./”)
filename_arr={}
i=0
for files in glob.glob(“*.py”):
filename_arr[i] = files
i += 1

for key, value in filename_arr.items():
print key, value

相关文章

python破解zip加密文件的方法

python破解zip加密文件的方法

首先我们先来桌面创建一个文件 我们创建了一个名为q的txt文件然后我们将它压缩,压缩的时候记得设置上密码 我这边将密码设置为123456, 接下来我们打开我们的编写工具,开始...

wxPython+Matplotlib绘制折线图表

wxPython+Matplotlib绘制折线图表

使用Matplotlib在wxPython的Panel上绘制曲线图,需要导入: import numpy from matplotlib.backends.backend_wxagg...

matplotlib 纵坐标轴显示数据值的实例

实例如下所示: import matplotlib as mt import numpy as np y=[7,0,0,0,0,0,1,25,98,333,471,0,322,42...

Python+django实现文件上传

1、文件上传(input标签)  (1)html代码(form表单用post方法提交) <input class="btn btn-primary col-md-1"...

python 获取url中的参数列表实例

Python的urlparse有对url的解析,从而获得url中的参数列表 import urlparse urldata = "http://en.wikipedia.org/w/...