title: How I can append bits in a file using Python?
body: <p>I am writing a program to read and write bits from a file to another file. I found a library called bitstring that helps to manipulate bits as strings. However, this library helps me to read bits, but I cannot write the read bits. Both inputs and outputs files have the same size, so it will be no problem in term of bytes. This is a part of my code.</p>
  <pre><code>import bitstring
  
  
  file = bitstring.ConstBitStream(filename='paper.pdf')
  print(file.length)
  
  bits_to_read = 5000000
  last_bits = 0
  
  while file.pos &lt; file.length-bits_to_read:
      bits = file.read(bits_to_read)
      str_bits = bitstring.BitArray(bits).bin
  
  
  
  rest = file.length - file.pos
  bits = file.read(rest)
  str_bits = bitstring.BitArray(bits).bin
  </code></pre>
  <p>with kind of regards.</p>