python 如何找到某一目录下的文件类型(三种方法)
2015-10-07 10:57
906 查看
#!/usr/bin/env python
print “#######Another One##########”
print “#######Another Two##########”
print “#######Another Three##########”
来源: </article/1279393.html>
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
来源: </article/1279393.html>
相关文章推荐
- 【Python】Learn Python the hard way, ex11 raw_input
- 【Python】Learn Python the hard way, ex10 转义字符
- 【Python】Learn Python the hard way, ex9 换行符,打印多行字符
- Python的Set和List的性能比较 + 两者之间的转换
- Python 将一个目录下的所有word文档转为txt
- 如何查询python帮助文档;sublime 快捷键
- Python 集合set添加删除、交集、并集、集合操作符号
- 之前写的python文件
- python文本处理
- 【Python】Learn Python the hard way, ex8 格式化字符串
- python实例:backup 备份
- 【Python】Learn Python the hard way, ex7 字符串连接
- 【Python】Learn Python the hard way, ex6 格式化字符串,多行文本
- Python学习笔记<字符串Str>
- Python学习笔记<字符串Str>
- leetcode之Rotate Image
- 用python进行项目实训的计划
- 【Python】Learn Python the hard way, ex5 格式化字符串
- 和声搜索算法-python实现
- 克隆选择算法-python实现