python - Find strings in list using wildcard -
i looking file names in list using wildcard.
from datetime import date dt = str("rt" + date.today().strftime('%d%m')) print dt # rt0701
basically need find pattern dt + "*.txt"
:
rt0701*.txt
in list:
l = ['rt07010534.txt', 'rt07010533.txt', 'rt02010534.txt']
how can loop?
you can use fnmatch.filter()
this:
import fnmatch l = ['rt07010534.txt', 'rt07010533.txt', 'rt02010534.txt'] pattern = 'rt0701*.txt' matching = fnmatch.filter(l, pattern) print(matching)
outputs:
['rt07010534.txt', 'rt07010533.txt']
Comments
Post a Comment