python搜索指定目录的方法

yipeiwu_com5年前Python基础

本文实例讲述了python搜索指定目录的方法。分享给大家供大家参考。具体分析如下:

#-------------------------------------
#      Name: search_directory.py
#     Author: Kevin Harris
# Last Modified: 02/13/04
# Description: This Python script demonstrates how to use os.walk()
#         to walk through a directory hierarchy
#         and list everything 
#         found.
#-------------------------------------
import os
for root, dirs, files in os.walk( os.curdir ):
 print( "root = " + root )
 for file in files:
 print( "file = " + file )
 for dir in dirs:
 print( "dir = " + dir )
 print( "\n" )
input( '\n\nPress Enter to exit...' )

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

相关文章

Python使用sorted排序的方法小结

Python使用sorted排序的方法小结

本文实例讲述了Python使用sorted排序的方法。分享给大家供大家参考,具体如下: # 例1. 按照元素出现的次数来排序 seq = [2,4,3,1,2,2,3] # 按次数排...

Python之自动获取公网IP的实例讲解

Python之自动获取公网IP的实例讲解

0.预备知识 0.1 SQL基础 ubuntu、Debian系列安装: root@raspberrypi:~/python-script# apt-get install mysql...

Python下的subprocess模块的入门指引

Python下的subprocess模块的入门指引

在熟悉了Qt的QProcess以后,再回头来看python的subprocess总算不觉得像以前那么恐怖了。 和QProcess一样,subprocess的目标是启动一个新的进程并与之进...

Python有序字典简单实现方法示例

Python有序字典简单实现方法示例

本文实例讲述了Python有序字典简单实现方法。分享给大家供大家参考,具体如下: 代码: # -*- coding: UTF-8 -*- import collections pri...

python多进程重复加载的解决方式

flask多进程会引起重复加载, 解决方法:把耗资源的加载挪到函数里面或者类里面,就不会重复加载资源了。 测试发现,不是flask引起的,是多进程会引起重复加载python文件。 把fl...