title: How do I remove a specific line out of a text file?
body: <pre class="lang-py prettyprint-override"><code>file = open(userid, "r+") 
  #userid is in the form
  # A
  # B
  # C
  # etc...
  removeRead = file.readlines()
  del removeRead[int(index)]
  file.write(str(removeRead))
  </code></pre>
  
  <p>This is what I've tried so far. Ive looked at other questions asking this and one of the suggestions was to 'simply iterate over the whole file and write all the lines except the one you want to remove`
  with their suggestion being </p>
  
  <pre class="lang-py prettyprint-override"><code>with open('fordel.txt') as f, open('out.txt', 'w') as fo:
      for linenum, line in enumerate(f, start=1):
          if linenum != badline:
              fo.write(line)
      # obviously not to my code
  
  </code></pre>
  
  <p>Is this really the simplest solution (i.e does python really not have an inbuilt solution for this?), and how exactly does it work so I can implement it into my code?</p>