Newbie: Joining Lists

mosscliffe mcl.office at googlemail.com
Thu May 17 05:49:57 EDT 2007


I have been playing with GLOB and OS.PATH and it all works, but is
there a better way of getting GLOB to recognise, multiple patterns at
one call (ONE).

Also is it possible to join lists, without the horrid concatenation
code I have (TWO).
I tried list.append(glob.glob(pattern)) but it error'd
----------------------- CODE ----------------------
import os
import glob

filenames = []
patterns = ('.\\t*.py', '.\\*.c??', '.\\*.txt') #  Can these patterns
for glob processing be specified in the glob call *****ONE****
for pattern in patterns:
    filenames = filenames + glob.glob(pattern)   # Is there a better
way for this line in joining lists *****TWO****

for fullfilename in filenames:
        (filepath, filename) = os.path.split(fullfilename)
        (shortname, extension) = os.path.splitext(filename)
        print "PATHNAME: %s FILENAME: %s SHORTNAME: %s EXTNAME: %s" %
(filepath, filename, shortname, extension[1:])
---------------------------------------------------------------------

Thanks

Richard

Ps  \\ is because I needed to get the path element for my test and
windoze does not return a path element  if in current directory




More information about the Python-list mailing list