title: Writing integers in binary to file in python
body: <p>How can I write integers to a file in binary in Python 3?</p>
  
  <p>For example, I want to write 6277101735386680763835789423176059013767194773182842284081 to a file in binary in exactly 24 bytes (unsigned, I will only be working with positive integers). How can I do this? I tried the following:</p>
  
  <pre><code>struct.pack("i", 6277101735386680763835789423176059013767194773182842284081)
  </code></pre>
  
  <p>This results in</p>
  
  <pre><code>ValueError: cannot fit 'int' into an index-sized integer
  </code></pre>
  
  <p>I have tried the same with some other formats ("l", "Q"), but those also result in errors:</p>
  
  <pre><code>struct.error: argument out of range
  </code></pre>
  
  <p>If I could convert the integer to exactly 24 bytes, I would be able to write to the file, since I know how to do that. However, I can't seem to convert the integers into bytes.</p>
  
  <p>Also, how do I make sure that exactly 24 bytes are written per integer? I will also be writing smaller numbers (1000, 2000, 1598754, 12), however those should also take 24 bytes.</p>
  
  <p>And how can I read the integers again from the file afterwards?</p>