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

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -