python搜索指定目录的方法

yipeiwu_com6年前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字典的核心底层原理讲解

Python字典的核心底层原理讲解

字典对象的核心是散列表。散列表是一个稀疏数组(总是有空白元素的数组),数组的每个单元叫做 bucket。每个 bucket 有两部分:一个是键对象的引用,一个是值对象的引用。所有 buc...

Python Django切换MySQL数据库实例详解

准备 软件 版本 Django 2.1.3 Pytho...

对YOLOv3模型调用时候的python接口详解

对YOLOv3模型调用时候的python接口详解

需要注意的是:更改完源程序.c文件,需要对整个项目重新编译、make install,对已经生成的文件进行更新,类似于之前VS中在一个类中增加新函数重新编译封装dll,而python接口...

python print输出延时,让其立刻输出的方法

一句print("ni hao"),很久看不见,怎么让python print能立刻输出呢。 因为python默认是写入stdout缓冲的,使用-u参数启动python,就会立刻输出了。...

pandas DataFrame实现几列数据合并成为新的一列方法

pandas DataFrame实现几列数据合并成为新的一列方法

问题描述 我有一个用于模型训练的DataFrame如下图所示: 其中的country、province、city、county四列其实是位置信息的不同层级,应该合成一列用于模型训练 方...