title: add text in a file with python (without replacing it)
body: <p>I have a file with ids and information, like this:</p>
  
  <pre><code>1oMZgkoaz3o 2011-12-29T01:23:00.000Z 9 503 ApolloIsMyCoPilot
  nUW1TomCSQg 2011-12-29T01:23:15.000Z 9 348 grea7stuff
  tJuLnRrAcs0 2011-12-29T01:26:20.000Z 9 123 AdelGaming
  tyi5g0mnPIs 2011-12-29T01:28:07.000Z 9 703 PreferredGaming
  </code></pre>
  
  <p>and I want to add a flag on some of the line, so if I have a dictionary</p>
  
  <pre><code>flags = {'1oMZgkoaz3o': flag1, 'tJuLnRrAcs0': flag2}
  </code></pre>
  
  <p>the result I want is </p>
  
  <pre><code>1oMZgkoaz3o 2011-12-29T01:23:00.000Z 9 503 ApolloIsMyCoPilot flag1
  nUW1TomCSQg 2011-12-29T01:23:15.000Z 9 348 grea7stuff
  tJuLnRrAcs0 2011-12-29T01:26:20.000Z 9 123 AdelGaming flag2
  tyi5g0mnPIs 2011-12-29T01:28:07.000Z 9 703 PreferredGaming
  </code></pre>
  
  <p>So I made this code</p>
  
  <pre><code>l = True
  while l is True:
      a = f.readline()
      try a.split(' ')[0] in flags.iterkeys():
          f.seek(-1,1)
          f.write(' '+str(flags[a.split(' ')[0]])+'\n')
          del flags[a.split(' ')[0]]
      except IndexError:
          l = False
  </code></pre>
  
  <p>so, my Python code could be poor, but the problem is that with this code I'm replacing text, so the file is all messed up. How can I write without replacing? and if you have better ideas for the code, you are welcome...</p>