相当于“ *” list all命令的python是什么?

时间:2019-10-01 15:32:57

标签: python-3.x

在其他语言中,我会使用类似于“ *”的什么字符来列出/查看所有文件,尽管开头部分是什么都没关系,但是如果说.traj,它们都将结束。

就像我想从目录中列出以下文件一样,

test1. exe
test1.traj
test2.exe
test2.traj
test3.exe
test3.traj

我只想列出的地方:

test1.traj
test2.traj
test3.traj

我可能会用其他语言:

print, *.traj

1 个答案:

答案 0 :(得分:0)

假设这是Python3,因为这就是您标记的内容。

使用glob module

像这样:

files = glob.glob('*.traj')

for f in files:
    print(f)