Skip to content
Advertisement

How do I convert a Python list into a C array by using ctypes?

If I have the follow 2 sets of code, how do I glue them together?

JavaScript

How can I call the c_function with a contiguous list of elements in x? I tried to cast x to a c_void_p, but that didn’t work.

I also tried to use something like

JavaScript

but this gets a syntax error.

The C code clearly wants the address of an array. How do I get this to happen?

Advertisement

Answer

The following code works on arbitrary lists:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement