append one file to another
Thomas Guettler
guettli at thomas-guettler.de
Tue Jul 12 09:51:37 EDT 2005
Am Tue, 12 Jul 2005 06:47:50 -0700 schrieb b83503104 at yahoo.com:
> Hi,
>
> I want to append one (huge) file to another (huge) file. The current
> way I'm doing it is to do something like:
>
> infile = open (infilename, 'r')
> filestr = infile.read()
> outfile = open(outfilename, 'a')
> outfile.write(filestr)
>
> I wonder if there is a more efficient way doing this?
> Thanks.
I guess (don't know), that this is faster:
for line in infile:
outfile.write(line)
At least if this a file with "lines".
If it is a binary file, you could read
N bytes at once: infile.read(N)
Thomas
--
Thomas Güttler, http://www.thomas-guettler.de/
More information about the Python-list
mailing list