How to concatenate external files ..?

Alexander Williams thantos at chancel.org
Thu Jun 29 05:47:22 EDT 2000


On Thu, 29 Jun 2000 04:20:49 -0400, Randolph MacKenzie <rmack at eznet.net> wrote:
>import sys, string, glob, os
>
>#First I create a list:
>fls = glob.glob('C:\\wxpython\\wxPython-2.1.16\\docs\\wx\\wx*.htm')
>
>#Then I guess I should open an output file for writing
>outfile = open('temp.txt,'r')
>
>Now what  .. how do I iterate over the list and specify that each file is to
>be read and appended to "outfile" ?

Well, at this point, you're in good shape.  Except outfile needs to be
opened with 'w', not 'r'.  Writing, not reading.

> for f in fls:
>     outfile.write(f.read())
>     print 'File %s written.' % f

There you go.  Bingo bango bongo, and its done.

-- 
Alexander Williams (thantos at gw.total-web.net)           | In the End,
  "Join the secret struggle for the soul of the world." | Oblivion
  Nobilis, a new Kind of RPG                            | Always
  http://www.chancel.org                                | Wins



More information about the Python-list mailing list