Python:os.listdir 替代/某些扩展 [英] Python: os.listdir alternative/certain extensions

查看:47
本文介绍了Python:os.listdir 替代/某些扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 os.listdir 命令查看具有某些扩展名的文件?我希望它能够工作,因此它可能只显示结尾带有 .f 的文件或文件夹.我查了文档,什么也没找到,所以别问了.

Is it possible to see files with certain extensions with the os.listdir command? I want it to work so it may show only files or folders with .f at the end. I checked the documentation, and found nothing, so don't ask.

推荐答案

glob 擅长于此:

import glob
for f in glob.glob("*.f"):
    print(f)

这篇关于Python:os.listdir 替代/某些扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆