title: Python C API: Parse args of string and integer in C
body: <p>Refering to <a href="http://mail.python.org/pipermail/python-dev/2009-June/090210.html" rel="nofollow noreferrer">http://mail.python.org/pipermail/python-dev/2009-June/090210.html</a>
  AND <a href="http://dan.iel.fm/posts/python-c-extensions/" rel="nofollow noreferrer">http://dan.iel.fm/posts/python-c-extensions/</a></p>
  
  <p>and here is other places i searched regarding my question:
  <a href="http://article.gmane.org/gmane.comp.python.general/424736" rel="nofollow noreferrer">http://article.gmane.org/gmane.comp.python.general/424736</a>
  <a href="http://joyrex.spc.uchicago.edu/bookshelves/python/cookbook/pythoncook-CHP-16-SECT-3.html" rel="nofollow noreferrer">http://joyrex.spc.uchicago.edu/bookshelves/python/cookbook/pythoncook-CHP-16-SECT-3.html</a>
  <a href="http://docs.python.org/2/c-api/sequence.html#PySequence_Check" rel="nofollow noreferrer">http://docs.python.org/2/c-api/sequence.html#PySequence_Check</a>
  <a href="https://stackoverflow.com/questions/8001923/python-extension-module-with-variable-number-of-arguments">Python extension module with variable number of arguments</a></p>
  
  <p>I am inexperienced in Python/C API. </p>
  
  <p>I have the following code:</p>
  
  <pre><code>sm_int_list = (1,20,3)
  c_int_array = (ctypes.c_int * len(sm_int_list))(*sm_int_list)
  sm_str_tuple = ('some','text', 'here')
  </code></pre>
  
  <p>On the C extension side, i have done something like this:</p>
  
  <pre><code>static PyObject* stuff_here(PyObject *self, PyObject *args)
  {
      char* input;
      int *i1, *i2;
      char *s1, *s2;
      // args = (('some','text', 'here'), [1,20,3], ('some','text', 'here'), [1,20,3])
      **PyArg_ParseTuple(args, "(s#:):#(i:)#(s#:):#(i:)#", &amp;s1, &amp;i1, &amp;s2, &amp;i2)**;
  /*stuff*/
  }
  </code></pre>
  
  <p>such that:
  stuff.here(('some','text', 'here'), [1,20,3], ('some','text', 'here'), [1,20,3])</p>
  
  <p>returns data in the same form as args after some computation.
  I would like to know the PyArg_ParseTuple expression, is it the proper way to parse</p>
  
  <ol>
  <li>an array of varying string</li>
  <li>an array of integers</li>
  </ol>
  
  <p><strong><em>UPDATE NEW</em></strong></p>
  
  <p>Is this the correct way?:</p>
  
  <pre><code>static PyObject* stuff_here(PyObject *self, PyObject *args)
      unsigned int tint[], cint[];
      ttotal=0, ctotal=0;
      char *tstr, *cstr;
      int *t_counts, *c_counts;
      Py_ssize_t size;
      PyObject *t_str1, *t_int1, *c_str2, *c_int2; //the C var that takes in the py variable value
      PyObject *tseq, cseq;
      int t_seqlen=0, c_seqlen=0;
  
  if (!PyArg_ParseTuple(args, "OOiOOi", &amp;t_str1, &amp;t_int1, &amp;ttotal,  &amp;c_str2, &amp;c_int2, &amp;ctotal))
      {
          return NULL;
      }
  
  if (!PySequence_Check(tag_str1) &amp;&amp; !PySequence_Check(cat_str2)) return NULL;
  
      else:
      {
          //All things t
          tseq = PySequence_Fast(t_str1, "iterable");
          t_seqlen = PySequence_Fast_GET_SIZE(tseq);
          t_counts = PySequence_Fast(t_int1);
  
          //All things c
          cseq = PySequence_Fast(c_str2);
          c_seqlen = PySequence_Fast_GET_SIZE(cseq);
          c_counts = PySequence_Fast(c_int2);
  
          //Make c arrays of all things tag and cat
          for (i=0; i&lt;t_seqlen; i++)
          {
              tstr[i] = PySequence_Fast_GET_ITEM(tseq, i);
              tcounts[i] = PySequence_Fast_GET_ITEM(t_counts, i);
          }
  
          for (i=0; i&lt;c_seqlen; i++)
          {
              cstr[i] = PySequence_Fast_GET_ITEM(cseq, i);
              ccounts[i] = PySequence_Fast_GET_ITEM(c_counts, i);
          }
  
  
      }
  </code></pre>
  
  <p>OR </p>
  
  <pre><code>PyArg_ParseTuple(args, "(s:)(i:)(s:)(i:)", &amp;s1, &amp;i1, &amp;s2, &amp;i2)
  </code></pre>
  
  <p>And then again while returning, </p>
  
  <p><code>Py_BuildValue("sisi", arr_str1,arr_int1,arr_str2,arr_int2)</code> ??</p>
  
  <p>Infact if someone could in detail clarify the various  PyArg_ParseTuple function that would be of great benefit. the Python C API, as i find it in the documentation, is not exactly a tutorial on things to do.</p>