栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

【python初级】os.listdir返回目录中包含的文件以及文件夹的列表

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【python初级】os.listdir返回目录中包含的文件以及文件夹的列表

【python初级】os.listdir返回目录中包含的文件以及文件夹的列表

背景示例

背景

os.listdir(path)返回一个列表,该列表中包含path目录下的文件以及文件夹。

查看python官方的说明:

import os
help(os.listdir)

运行返回:

Help on built-in function listdir in module nt:

listdir(path=None)
    Return a list containing the names of the files in the directory.
    
    path can be specified as either str or bytes.  If path is bytes,
      the filenames returned will also be bytes; in all other circumstances
      the filenames returned will be str.
    If path is None, uses the path='.'.
    On some platforms, path may also be specified as an open file descriptor;
      the file descriptor must refer to a directory.
      If this functionality is unavailable, using it raises NotImplementedError.
    
    The list is in arbitrary order.  It does not include the special
    entries '.' and '..' even if they are present in the directory.
示例

简单的演示os.listdir(path)的使用:

# jn10010537
import os
path="./test"
result=os.listdir(path)
print(">>>result:",result)

运行如下:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/725910.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号