How to concatenate external files ..?
Alexander Williams
thantos at chancel.org
Thu Jun 29 07:01:50 EDT 2000
On Thu, 29 Jun 2000 09:59:15 GMT, richard_chamberlain at my-deja.com
<richard_chamberlain at my-deja.com> wrote:
> file=open(x,'r')
Teach me to post while still mostly asleep here at the office. I
forgot entirely about opening the iterated filename for reading.
Bugger.
To try and make up for it, how about this wee gem?
> # "fls" is the globbed list of filenames
> # "outfile" is the file object already opened to write to
> flsHandles = map(lambda f: open(f, 'r').read, fls)
> for fH in flsHandles:
> outfile.write(fH())
Note that you never explicitly give each opened file its own name;
instead, you create a list of all the read methods of all the file
objects created dynamically from the list of filenames. (That refered
to by "open(FILENAME, 'r').open" is just a function/method reference,
it can still be invoked.)
--
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