title: ctypes variable length structures
body: <p>Ever since I read Dave Beazley's post on binary I/O handling (http://dabeaz.blogspot.com/2009/08/python-binary-io-handling.html) I've wanted to create a Python library for a certain wire protocol. However, I can't find the best solution for variable length structures. Here's what I want to do:</p>
  
  <pre><code>import ctypes as c
  
  class Point(c.Structure):
      _fields_ = [
          ('x',c.c_double),
          ('y',c.c_double),
          ('z',c.c_double)
          ]
  
  class Points(c.Structure):
      _fields_ = [
          ('num_points', c.c_uint32),
          ('points', Point*num_points) # num_points not yet defined!
          ]
  </code></pre>
  
  <p>The class <code>Points</code> won't work since <code>num_points</code> isn't defined yet. I could redefine the <code>_fields_</code> variable later once <code>num_points</code> is known, but since it's a class variable it would effect all of the other <code>Points</code> instances. </p>
  
  <p>What is a pythonic solution to this problem?</p>