如何使用pathlib来显示两种模式? [英] How to glob two patterns with pathlib?
本文介绍了如何使用pathlib来显示两种模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想找到两种具有两种不同扩展名的文件:.jl
和.jsonlines
.我用
I want find two types of files with two different extensions: .jl
and .jsonlines
. I use
from pathlib import Path
p1 = Path("/path/to/dir").joinpath().glob("*.jl")
p2 = Path("/path/to/dir").joinpath().glob("*.jsonlines")
但我希望p1
和p2
作为一个变量而不是两个.我应该首先合并p1
和p2
吗?还有其他方法来修饰glob的图案吗?
but I want p1
and p2
as one variable not two. Should I merge p1
and p2
in first place? Are there other ways to concatinate glob's patterns?
推荐答案
尝试一下:
from os.path import join
from glob import glob
files = []
for ext in ('*.jl', '*.jsonlines'):
files.extend(glob(join("path/to/dir", ext)))
print(files)
这篇关于如何使用pathlib来显示两种模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文