Ben Chuanlong Du's Blog

It is never too late to learn.

Hands on the Python module glob

Comment

  1. pathlib.Path.glob is preferred to the glob module!!

  2. The list returned is not sorted.

In [2]:
import glob
In [9]:
files = glob.glob("*.markdown")
files[:5]
Out[9]:
['2019-10-13-git-shell-on-windows.markdown',
 '2012-10-22-containers-in-java.markdown',
 '2019-10-01-tips-on-pyspark.markdown',
 '2020-03-03-common-issues-in-pytorch.markdown',
 '2014-09-14-some-terminologies-in-aml.markdown']
In [11]:
sorted(files)[:5]
Out[11]:
['2010-11-20-general-tips-for-latex.markdown',
 '2012-05-17-java-difference-abstract-interface.markdown',
 '2012-06-05-free-online-tools-for-developers.markdown',
 '2012-06-08-softwares-windows.markdown',
 '2012-06-10-operators-popular-language.markdown']
In [12]:
glob.glob("*pop*")
Out[12]:
['2019-02-17-popular-data-structures-in-python.markdown',
 '2020-02-25-popular-and-useful-modules-and-functions-in-pytorch.markdown',
 '2012-06-10-operators-popular-language.markdown']
In [ ]:
 

Comments