Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A ctypes array is initialized with positional arguments. An initial value can be a ctypes data object, a Python object compatible with a simple data type (for an array of simple types such as <code>c_int * 20</code>), or a tuple of positional arguments used to create a temporary instance of the array's data type to be copied (<code>memcpy</code>) into the array. </p> <p>Since you need a keyword argument to select the proper converter, you'll have to either call <code>MyValue</code> to manually create the temporary instance, or call <code>setattr</code> on each item of an unitialized array. For the former, you can use a generator expression combined with <code>*</code> and <code>**</code> unpacking (see the <a href="http://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists" rel="nofollow">tutorial</a>):</p> <pre><code>values = [ ('ftInt', 12), ('ftString', 'testing'), ] arr = MyValues(*(MyValue(**{k: v}) for k, v in values)) </code></pre> <p>And here's an alternative using <a href="http://docs.python.org/2/library/functions.html#setattr" rel="nofollow"><code>setattr</code></a> to update the array in a loop:</p> <pre><code>arr = MyValues() for item, value in zip(arr, values): setattr(item, *value) # note the * unpacking </code></pre> <hr> <p>It would be nice to add support for a keyword argument dict in <a href="http://hg.python.org/cpython/file/ab05e7dd2788/Modules/_ctypes/_ctypes.c#l2850" rel="nofollow"><code>_PyCData_set</code></a> (Modules/ctypes/_ctypes.c).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload