File processing

Peter Hansen peter at engcorp.com
Mon Feb 17 13:36:15 EST 2003


fishers wrote:
> 
> Thanks for your response. What I am trying to do in this case is just to
> join one file (e.g. 'two.txt') to the end of another (e.g. 'one.txt'). I
> could tell from your answer that there are two ways to approach this. It
> seemed to me though that using open (or file?) would then involve some code
> to copy the data from the two.txt to one.txt. I was just trying to avoid
> this.

(untested)

baseFile = file('one.txt', 'ab')
addFile = file('two.txt', 'rb')
baseFile.write(addFile.read())

Doesn't seem like that much work to me... (note: 'b' used for safety
under Windows.)

-Peter




More information about the Python-list mailing list