Yours in namelessness (was: How to concatenate external files ..?)
Cameron Laird
claird at starbase.neosoft.com
Thu Jun 29 11:21:03 EDT 2000
More information about the Python-list mailing list
Thu Jun 29 11:21:03 EDT 2000
- Previous message (by thread): How to concatenate external files ..?
- Next message (by thread): Yours in namelessness (was: How to concatenate external files ..?)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <slrn8lmb4t.lpi.thantos at brimstone.mecha>, Alexander Williams <thantos at gw.total-web.net> wrote: >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.) . . . Well, let's get even more anonymous, and suggest for fH in = map(lambda f: open(f, 'r').read, fls): outfile.write(fH()) -- Cameron Laird <claird at NeoSoft.com> Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html
- Previous message (by thread): How to concatenate external files ..?
- Next message (by thread): Yours in namelessness (was: How to concatenate external files ..?)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list