When Python is embedded into the implementation of tuples in C/C ++, you need related functions. Create a new tuple. The following is a detailed description of the relevant content. I hope you will find what you want from this article, this gives you a better understanding of how to embed Python into the tuples in C/C ++.
Python embedding tuples in C/C ++The Python/c api provides the PyTuple_New () function to create a new Python tuples. The PyTuple_New () function returns the created tuples. The function prototype is as follows.
PyObject * PyTuple_New (Py_ssize_t len)
The parameter meanings are as follows.
- Application of Three simple functions in multiple threads in Python
- Python Thread Programming solves the problem of different speeds in asynchronous threads
- Python embedded in C/C + has very powerful application functions
- Python unicode ascii code on windows
- Introduction to two common functions in lower-level Python embedding
· Len: the length of the created tuples. After the tuples are created, you can use the PyTuple_SetItem () function to add items to the tuples. The function prototype is as follows.
Int PyTuple_SetItem (PyObject * p, Py_ssize_t pos, PyObject * o)
The parameter meanings are as follows.
· P: The operation tuples.
· Pos: The Position Index of the added item.
· O: the added item value.
You can use the PyTuple_GetItem () function in Python/c api to obtain the value of an item in the tuples. The value of the return item of the PyTuple_GetItem () function. The function prototype is as follows.
PyObject * PyTuple_GetItem (PyObject * p, Py_ssize_t pos)
The parameter meanings are as follows.
· P: The tuples to be operated.
· Pos: The Position Index of the item.
After the tuples are created, you can use the _ PyTuple_Resize () function to re-adjust the size of the tuples. The function prototype is as follows.
Int _ PyTuple_Resize (PyObject ** p, Py_ssize_t newsize)
The parameter meanings are as follows.
· P: pointer to the tuples to be operated.
· Newsize: the size of the new element group.
The above article introduces how to embed tuples in C/C ++ in Python.