title: Writing in file's actual position in Python
body: <p>I want to read a line in a file and insert the new line ("\n") character in the n position on a line, so that a 9-character line, for instance, gets converted into three 3-character lines, like this:</p>
  
  <pre><code>"123456789" (before)
  "123\n456\n789" (after)
  </code></pre>
  
  <p>I've tried with this:</p>
  
  <pre><code>f = open(file, "r+")
  f.write("123456789")
  f.seek(3, 0)
  f.write("\n")
  f.seek(0)
  f.read()
  </code></pre>
  
  <p>-> '123\n56789'</p>
  
  <p>I want it not to substitute the character in position n, but only to insert another ("\n") char in that position.</p>
  
  <p>Any idea about how to do this?
  Thanks</p>