Search code examples
pythonccpython

How can we pass a C structure to Python?


I'm a new in both C and Python. These days, I'm learning to embed Python in C. As I am calling Python functions from C, I'd like to know, how can we pass a C structure to Python?

thanks alot in advance!


Solution

  • The cleanest thing to do is probably to create a new type and implement tp_getattr, either returning the appropriate member of the struct or raising an exception depending on the argument passed.