title: Accessing C struct array to Python with SWIG
body: <p>I attempting to call into existing C code from Python. The C code defines a struct <code>B</code> that contains an struct array of <code>A</code>s. The C code also defines a function that puts values into the structure when called. I can access the array member variable, but it is not an list (or something that supports indexing). Instead, I am getting an object that is a proxy for <code>B*</code>.</p>
  
  <p>I found <a href="https://stackoverflow.com/q/5670456/210526">this question</a>, but it doesn't look like it was completely resolved. I'm also not sure how to make an instance of the Python class <code>B</code> to replace the <code>PyString_FromString()</code>.</p>
  
  <p>Below is the code needed to demonstrate my issue and how to execute it:</p>
  
  <p>example.h</p>
  
  <pre><code>typedef struct A_s
  {
    unsigned int thing;
    unsigned int other;
  } A_t;
  
  typedef struct B_s
  {
    unsigned int size;
    A_t items[16];
  } B_t;
  
  unsigned int foo(B_t* b);
  </code></pre>
  
  <p>example.c</p>
  
  <pre><code>#include "example.h"
  
  unsigned int
  foo(B_t* b)
  {
    b-&gt;size = 1;
    b-&gt;items[0].thing = 1;
    b-&gt;items[0].other = 2;
  }
  </code></pre>
  
  <p>example.i</p>
  
  <pre><code>%module example
  %{
  #define SWIG_FILE_WITH_INIT
  #include "example.h"
  %}
  
  %include "example.h"
  </code></pre>
  
  <p>setup.py</p>
  
  <pre><code>from distutils.core import setup, Extension
  
  module1 = Extension('example', sources=['example.c', 'example.i'])
  setup(name='Example', version='0.1', ext_modules=[module1])
  </code></pre>
  
  <p>script.py - This uses library and demonstrates the failure.</p>
  
  <pre><code>import example
  b = example.B_t()
  example.foo(b)
  print b.size
  print b.items
  for i in xrange(b.size):
      print b.items[i]
  </code></pre>
  
  <p>How to run everything:</p>
  
  <pre><code>python setup.py build_ext --inplace
  mv example.so _example.so
  python script.py
  </code></pre>