Skip to content

Instantly share code, notes, and snippets.

@travis23
Last active June 1, 2019 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travis23/802c5379fd4bc275331bf9fa8d306e99 to your computer and use it in GitHub Desktop.
Save travis23/802c5379fd4bc275331bf9fa8d306e99 to your computer and use it in GitHub Desktop.
[filename pattern matching] #python #filename #fnmatch
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