List comprehensions and glob

Robin Becker robin at reportlab.com
Thu Jul 15 03:42:32 EDT 2004


I want to use a list of glob patterns to create a single flat list of files

eg

P = ['*.txt','*.py']

I expected I would somehow be able to use list comprehensions to do 
this, but in the end I could only do this hackish thing

import operator, glob
F = reduce(operator.add,[glob.glob(p) for p in P],[])


is there a more pythonic approach?
-- 
Robin Becker



More information about the Python-list mailing list