Skip to content

Instantly share code, notes, and snippets.

@e96031413
Created January 12, 2020 07:11
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 e96031413/19db962a7c5274086de02639cc6d4303 to your computer and use it in GitHub Desktop.
Save e96031413/19db962a7c5274086de02639cc6d4303 to your computer and use it in GitHub Desktop.
The official example of glob
>>> import glob
>>> glob.glob('./[0-9].*')
['./1.gif', './2.txt']
>>> glob.glob('*.gif')
['1.gif', 'card.gif']
>>> glob.glob('?.gif')
['1.gif']
>>> glob.glob('**/*.txt', recursive=True)
['2.txt', 'sub/3.txt']
>>> glob.glob('./**/', recursive=True)
['./', './sub/']
>>> import glob
>>> glob.glob('*.gif') #find .gif file
['card.gif']
>>> glob.glob('.c*') #find .gif file whose names start with.
['.card.gif']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment