-1

I am writing some code in C, which reads data in and stores it in a pointer of type;

uint8_t

This data I now want to make accessible in Python3.

For now I have figured out how to make my C code callable with the help of ctypes and I know it works since I am able to print my data out in the Python terminal, but not able to store it in a variable.

My problem lies in that I do not know how to transform this pointer into an array which can be stored and manipulated in Python, so therefore I ask, if someone has a simple example where they move for an example a 3 by 1 array from C into Python, and then are able to work with it there, it would benefit me a lot.

2
  • This is either a duplicate of stackoverflow.com/questions/10628337/… or stackoverflow.com/questions/14584439/… depending on what you're using to wrap your C code (your question and tags tell me different things). Commented Nov 4, 2019 at 7:51
  • Thanks, still new to C, so I really struggle at looking at others code right now, but managed to find a solution my self. Thanks, for commenting Commented Nov 4, 2019 at 18:05

1 Answer 1

0

Okay, so I managed to figure it out, maybe not the smartest way, but atleast it works now. Since I return a pointer of the type, ``` u_int8 * ```` in C, I amble then in Python to use something like this:

g = (ctypes.c_float*5271).from_address(a)

And then g[0], g[:], etc. to get the data etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.