How to write a binary file filled with zeros as binary digits?
<p>How can I write a binary file filled with zeros as binary digits? </p>

<p>For example I have 8 bits of zeros like 00000000 which will be saved as one byte.</p>

<p>Files are sequences of bytes, and Python trivially lets you write bytes. Just write <code>\x00</code> characters to produce byes that consist of nothing but <code>0</code> bits.</p>

<p>Open the file as binary and just write as many such bytes as you need:</p>

<pre><code>with open(filename, 'wb') as binfile:
    binfile.write(b'\x00' * desired_length)
</code></pre>

python binary