title: SWIG Python Structure Array
body: <p>I've been searching for a few days trying to figure out how to turn an array of structures into a Python list. I have a function that returns a pointer to the beginning of the array.</p>
  
  <pre><code>struct foo {
      int member;
  };
  
  struct foo *bar() {
      struct foo *t = malloc(sizeof(struct foo) * 4);
      ... do stuff with the structs ...
      return t;
  }
  </code></pre>
  
  <p>After calling the function from Python I get a single structure but trying to access the other elements of the array causes an error:</p>
  
  <pre><code>foo = bar()
  print foo[1].member
  TypeError: 'foo' object does not support indexing
  </code></pre>
  
  <p>I've tried using <code>%array_class</code> but to no avail. I've also tried defining the function as returning an array in the SWIG interface file:</p>
  
  <pre><code>extern struct foo [ANY] bar();
  </code></pre>
  
  <p>The SWIG documentation is pretty thorough but I can't seem to figure this out. </p>