python 如何找到某一目录下的文件类型(三种方法)
2024-10-10 03:34:14
#!/usr/bin/env python
import glob
import os
os.chdir(“./”)
for file in glob.glob(“*.py”):
print file
print “#######Another One##########”
import os
for file in os.listdir(“./”):
if file.endswith(“.py”):
print file
print “#######Another Two##########”
import os
for root, dirs, files in os.walk(“./”):
for file in files:
if file.endswith(“.py”):
print os.path.join(root, file)
print “#######Another Three##########”
import os
import glob
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
最新文章
- PHP storm快捷键
- SQL查询表字段的信息
- nginx基于IP的虚拟主机
- AndroidStudio 中的坑Error:(1, 0) Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRID
- SpringMVC接收参数的注解笔记
- ACCESS 数据库使用配置调整解决方案
- SharedPreferences详解
- JavaWeb项目开发案例精粹-第6章报价管理系统-05Action层
- CSS居中的方法整合--水平居中
- iOS动画原理
- [OC Foundation框架 - 7] NSArray的创建与遍历
- 从源码编译rpi的内核
- Discuz论坛下载与安装
- OC可变參数的函数实现va_start、va_end、va_list的使用
- mvn profile 深层次目录打参数核心配置
- 收藏的一些javascript片段
- 3407: [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题
- IDEA右侧 Maven oracle依赖包有红色波浪线
- Sudoku 小项目
- 论文阅读笔记三十四:DSSD: Deconvolutiona lSingle Shot Detector(CVPR2017)
热门文章
- Hibernate3.3用户手册摘要-1-辅助类,session
- Load an X509 PEM file into Windows CryptoApi
- 安卓集成发布详解(二)gradle
- iframe获取父、子窗口的方法
- Expecting ";jsp:param"; standard action with ";name"; and ";value"; attributes错误
- 242. Valid Anagram
- 值得推荐的C/C++框架和库 (真的很强大)
- POJ 2411 Mondriaan'sDream(状压DP)
- c#(特殊集合)
- redis 安装并设置为开机启动服务