Joining Big Files

Paul McGuire ptmcg at
Sun Aug 26 03:15:39 CEST 2007

On Aug 25, 4:57 am, mosscliffe < at> wrote:
> I have 4 text files each approx 50mb.

<yawn> 50mb? Really?  Did you actually try this and find out it was a

Try this:
import time

start = time.clock()
outname = "temp.dat"
outfile = file(outname,"w")
for inname in ['file1.dat', 'file2.dat', 'file3.dat', 'file4.dat']:
    infile = file(inname)
    outfile.write( )
end = time.clock()

print end-start,"seconds"

For 4 30Mb files, this takes just over 1.3 seconds on my system.  (You
may need to open files in binary mode, depending on the contents, but
I was in a hurry.)

-- Paul

More information about the Python-list mailing list