Skip to content
Advertisement

Tag: ctypes

Python Ctypes: Convert returned C array to python list, WITHOUT numpy

I am using Python Ctypes to access some C library. One of the functions I connected to, returns const *double, which is actually an array of doubles. When I get the result in Python, how can I convert this array to a python list? The signature of the C function: Let’s assume that it returns an array that contains 0.13

Pass a 2d numpy array to c using ctypes

What is the correct way to pass a numpy 2d – array to a c function using ctypes ? My current approach so far (leads to a segfault): C code : Python code: Answer This is probably a late answer, but I finally got it working. All credit goes to Sturla Molden at this link. The key is, note that

ctypes variable length structures

Ever since I read Dave Beazley’s post on binary I/O handling (http://dabeaz.blogspot.com/2009/08/python-binary-io-handling.html) I’ve wanted to create a Python library for a certain wire protocol. However, I can’t find the best solution for variable length structures. Here’s what I want to do: The class Points won’t work since num_points isn’t defined yet. I could redefine the _fields_ variable later once num_points

Advertisement