Reputation: 506
I have directory having file names "VISCUS","MISMANAGE" etc i want to find files matching given pattern.
pattern = "SALES" # this changes dynamically as command-line args I am doing like below
import glob
files_present = glob.glob(r"*pattern*")
#glob.glob(r"*SALES*")works okay
Upvotes: 0
Views: 426
Reputation: 46859
something like this?
for pattern in ("VISCUS", "MISMANAGE"):
files_present = glob.glob(r"*{}*".format(pattern))
# do stuff with present files
you create the glob
string from the loop variable.
Upvotes: 0
Reputation: 12140
'*pattern*'
will not change to '*SALES*'
. Try this:
pattern = "SALES"
import glob
files_present = glob.glob(r"*{}*".format(pattern))
Upvotes: 1