Reputation: 1
I am trying to use glob.glob() to get a list of files that comes from different directories with two kinds of suffix.
For example, the files i am going to read are
/ABC/DEF/HIJ/*.{data,index}
and
/ABC/LMN/HIJ[0-3]/*.{data,index}
I was asked to do it with only a single glob.glob() call. How can I do it? Thanks.
Upvotes: 0
Views: 133
Reputation: 142
You could try using a list comprehension (if this fits your single call criteria),
files_wanted = ['/ABC/DEF/HIJ/*.data', '/ABC/DEF/HIJ/*.index', '/ABC/LMN/HIJ[0-3]/*.data', '/ABC/LMN/HIJ[0-3]/*.index'] #List containing your regular expressions.
files_list = [glob.glob(re) for re in files_wanted] #List comprehension.
Hope this works for you!
Upvotes: 1