Read number of CSV files

Peter Otten __peter__ at
Mon Nov 12 18:50:25 CET 2012

Peter Otten wrote:

[please don't email me directly]

> How is using glob different from os.listdir() Peter?

glob retains the path and allows you to filter the files. Compare:

>>> import os, glob
>>> os.listdir("alpha")
['', '', 'one.txt', '', 'three.txt', 'two.txt']
>>> glob.glob("alpha/*")
['alpha/', 'alpha/', 'alpha/one.txt', 'alpha/', 
'alpha/three.txt', 'alpha/two.txt']
>>> glob.glob("alpha/*.py")
['alpha/', 'alpha/', 'alpha/']

See the documentation for more.

More information about the Python-list mailing list