Unable to Concatenate a file - destination kept getting overwritten

Foster Rilindo rilindo at me.com
Fri Apr 20 22:11:46 EDT 2012


Nevermind. Dumb mistake. 

I should have used:

destination = open(disk1,'ab')

Doh.

On Apr 20, 2012, at 8:03 PM, Foster Rilindo wrote:

> I can't seem to concatenate.
> 
> I got binary files here:
> 
> yvaine:disk rilindo$ ls -lah
> total 61440
> drwxr-xr-x   4 rilindo  staff   136B Apr 20 19:47 .
> drwxr-xr-x  10 rilindo  staff   340B Apr 20 19:45 ..
> -rw-r--r--   1 rilindo  staff    20M Apr 20 20:00 disk1
> -rw-r--r--   1 rilindo  staff    10M Apr 20 19:47 disk2
> 
> Based on the following code, I should be able to cat disk2 over to disk 1, resulting in a 30 Meg file:
> 
>>>> import shutil
>>>> import os
>>>> disk1="/Users/rilindo/tmp/disk/disk1"
>>>> disk2="/Users/rilindo/tmp/disk/disk2"
>>>> destination = open(disk1,'wb')
>>>> shutil.copyfileobj(open(disk2,'rb'),destination)
>>>> destination.close()
> 
> However, the result is that the destination gets overwritten:
> 
> yvaine:disk rilindo$ ls -lah
> total 40960
> drwxr-xr-x   4 rilindo  staff   136B Apr 20 19:47 .
> drwxr-xr-x  10 rilindo  staff   340B Apr 20 19:45 ..
> -rw-r--r--   1 rilindo  staff    10M Apr 20 20:02 disk1
> -rw-r--r--   1 rilindo  staff    10M Apr 20 19:47 disk2
> 
> Is this right way to concatenate a file or is there a better way?
> 
> - Rilindo
> -- 
> http://mail.python.org/mailman/listinfo/python-list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120420/be7e13a3/attachment-0001.html>


More information about the Python-list mailing list