title: seek(), then read(), then write() in python
body: <p>When running the following python code:</p>
  
  <pre><code>&gt;&gt;&gt; f = open(r"myfile.txt", "a+")        
  &gt;&gt;&gt; f.seek(-1,2)                                        
  &gt;&gt;&gt; f.read()                                            
  'a'                                                     
  &gt;&gt;&gt; f.write('\n')                                        
  </code></pre>
  
  <p>I get the following (helpful) exception:</p>
  
  <pre><code>Traceback (most recent call last):      
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;   
  IOError: [Errno 0] Error        
  </code></pre>
  
  <p>The same thing happens when openning with "r+". </p>
  
  <p>Is this supposed to fail? Why? </p>
  
  <p>Edit:</p>
  
  <ol>
  <li>Obviously, this is just an example, not what I am actually trying to execute. My actual goal was to verify that the files ends with "\n", or add one, before adding the new lines. </li>
  <li>I am working under Windows XP, and they problem exists in both Python 2.5 and Python 2.6. </li>
  <li><p>I managed to bypass the problem by calling seek() again:</p>
  
  <blockquote>
    <blockquote>
      <blockquote>
        <p>f = open(r"myfile.txt", "a+")<br>
        f.seek(-1,2)<br>
        f.read()<br>
        'a'<br>
        f.seek(-10,2)<br>
        f.write('\n')     </p>
      </blockquote>
    </blockquote>
  </blockquote></li>
  </ol>
  
  <p>The actual parameters of the 2nd seek call don't seem to matter. </p>