title: Python 3: Idiomatic way to delete last char in file
body: <p>Is there an idiomatic way to do this? I just upgraded from Python 2 to Python 3 and I'm trying to port my script, and I gotta say I'm not impressed. From what I can tell, my code gets to go</p>
  
  <p>from this</p>
  
  <pre><code># Not allowed by Python 3 anymore without being in binary mode.
  card_names_file.seek(-1, os.SEEK_END)
  if card_names_file.read() == ',':
      card_names_file.truncate()
  </code></pre>
  
  <p>to this</p>
  
  <pre><code># Go to end of file just to get position index. lawl.
  card_names_file.seek(0, os.SEEK_END)
  # Create a temporary just to store said index. More lawl.
  eof = card_names_file.tell()
  # Index one from the back. ugh. w/e, that's fine.
  card_names_file.seek(eof - 1, os.SEEK_SET)
  
  # Oh wait, .read() will advance my pointer. Oh hey Python 3 doesn't let me
  # use .peek() either. Fantastic. I'll have to read this...
  if card_names_file.read() == ',':
      # Then go back to where I was by indexing from front AGAIN
      card_names_file.seek(eof - 1, os.SEEK_SET)
      # Then remove last character.
      card_names_file.truncate()
  </code></pre>
  
  <p>This is the dumbest code I've almost ever seen and I've spent 2 and a half hours so far trying to delete a character from the back of a file, and this looks like a hack.</p>
  
  <p>The alternative is that I have code that looks like this</p>
  
  <pre><code># open file
  with open(file, a+)
      # do stuff
  
  # open same file
  with open(file, w+b)
      # do different stuff
  </code></pre>
  
  <p>But I can't actually get that to work either.</p>