Last active
June 1, 2019 23:28
-
-
Save travis23/802c5379fd4bc275331bf9fa8d306e99 to your computer and use it in GitHub Desktop.
[filename pattern matching] #python #filename #fnmatch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fnmatch | |
pattern = "aaa_*" # Special characters '*' and '?' | |
list_of_all_files = ['aaa_1.json', 'a.json', 'b.json'] | |
for filename in list_of_all_files: | |
if fnmatch.fnmatch(filename, pattern): | |
print(filename) | |
# Output: aaa_1.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment