Newbie: Joining Lists

7stud bbxx789_05ss at yahoo.com
Thu May 17 12:22:08 EDT 2007


On May 17, 3:49 am, mosscliffe <mcl.off... at googlemail.com> wrote:
> 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).
>

A better way?  You haven't posted a way to do that.  And a quick
perusal of the docs for the glob module shows that glob uses some very
simplistic unix like pattern matching, and there are only 4 symbols
you can use.  None of them allow alternate patterns, so, no, you can't
match multiple patterns in one pass.  You can use os.listdir() and
regexes if you want.

> Also is it possible to join lists, without the horrid concatenation
> code I have

Horrid?  What did you have in mind?  You can use the += operator:

filenames += glob.glob(pattern)

If your aversion to concatenation runs too deep, you could use a loop:

for file in glob.glob(pattern):
    filenames.append(file)





More information about the Python-list mailing list