how do I insert data to an arbitrary location in a binary file without overwriting existing file data?
<p>I've tried to do this using the 'r+b',  'w+b', and 'a+b' modes for <code>open()</code>. I'm using with <code>seek()</code> and <code>write()</code> to move to and write to an arbitrary location in the file, but all I can get it to do is either 1) write new info at the end of the file or 2) overwrite existing data in the file. 
Does anyone know of some other way to do this or where I'm going wrong here?</p>

<p>What you're doing wrong is assuming that it can be done.  :-)</p>

<p>You don't get to insert and shove the existing data over; it's already in that position on disk, and overwrite is all you get.</p>

<p>What you need to do is to mark the insert position, read the remainder of the file, write your insertion, and then write that remainder <em>after</em> the insertion.</p>

python file binaryfiles file-writing