title: How do I save a binary buffer allocated via ctype malloc to a file in Python?
body: <p>I have the following code</p>
  
  <pre><code>import ctypes
  pBuf = ctypes.cdll.msvcrt.malloc(nBufSize)
  # wrote something into the buffer
  </code></pre>
  
  <p>How do I save the content of the buffer to a file using Python 2.5?</p>
  
  <p>As you may already know, this is not going to work, giving <code>TypeError: argument 1 must be string or read-only buffer, not int</code>:</p>
  
  <pre><code>f = open("out.data","wb"
  f.write(pBuf)
  </code></pre>