How to embed Python into Candlestick + tuple and its application
This article introduces you how to embed Python into the CCMG + tuple and the application. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Embed Python into the tuple operation of Candlestick +
The PyTuple_New () function is provided in Python/C API to create a new Python tuple. The PyTuple_New () function returns the tuple you created. The function prototype is shown below.
PyObject* PyTuple_New (Py_ssize_t len)
The meaning of the parameters is as follows.
Len: the length of the tuple created.
After the tuple is created, you can use the PyTuple_SetItem () function to add items to the tuple. The function prototype is shown below.
Analysis of Tailspin Travel U in ASP.NET MVC 2
Define future Web styles CSS 3 latest features at a glance
Python embeds C++ to make up for the shortcomings of C++ itself.
An introduction to the powerful functions of embedding Python into CumberCraft +
Required for Python embedding in C _ Candle + (lower level embedding)
Int PyTuple_SetItem (PyObject * p, Py_ssize_t pos, PyObject * o)
The meaning of the parameters is as follows.
P: the tuple of the operation.
Pos: the location index of the item being added.
O: the item value added.
You can use the PyTuple_GetItem () function in Python/C API to get the value of an item in a tuple. The PyTuple_GetItem () function returns the value of the item. The function prototype is shown below.
PyObject* PyTuple_GetItem (PyObject* p, Py_ssize_t pos)
The meaning of the parameters is as follows.
P: the tuple to operate on.
Pos: the location index of the item.
After the tuple is created, you can resize the tuple using the _ PyTuple_Resize () function. The function prototype is shown below.
Int _ PyTuple_Resize (PyObject * * p, Py_ssize_t newsize)
The meaning of the parameters is as follows.
P: a pointer to the tuple to operate on.
Newsize: the size of the new tuple.
Embed Python into dictionary operation
The PyDict_New () function is provided in Python/C API to create a new dictionary. The PyDict_New () function returns the dictionary created. The function prototype is shown below.
PyObject* PyDict_New ()
When the dictionary is created, you can use the PyDict_SetItem () function and the PyDict_SetItemString () function to add items to the dictionary. The function prototypes are shown below.
Int PyDict_SetItem (PyObject * p, PyObject * key, PyObject * val)
Int PyDict_SetItemString (PyObject * p, const char * key, PyObject * val)
The meaning of the parameters is as follows.
P: the dictionary to operate on.
Key: keyword for adding items, PyObject for the PyDict_SetItem () function and char for the PyDict_SetItemString () function.
Val: add the value of the item.
Use the PyDict_GetItem () function and the PyDict_GetItemString () function in Python/C API to get the value of an item in the dictionary. They all return the value of the item. The function prototypes are shown below.
PyObject* PyDict_GetItem (PyObject* p, PyObject* key)
PyObject* PyDict_GetItemString (PyObject* p, const char * key)
The meaning of the parameters is as follows.
P: the dictionary to operate on.
Key: keyword for adding items, PyObject for the PyDict_GetItem () function and char for the PyDict_GetItemString () function.
You can delete an entry in the dictionary using the PyDict_DelItem () function and the PyDict_DelItemString () function in Python/C API. The function prototype is shown below.
Int PyDict_DelItem (PyObject * p, PyObject * key)
Int PyDict_DelItemString (PyObject * p, char * key)
The meaning of the parameters is as follows.
P: the dictionary to operate on.
Key: keyword for adding items, PyObject for the PyDict_DelItem () function and char for the PyDict_DelItemString () function.
The dictionary can be traversed using the PyDict_Next () function in Python/C API. The function prototype is shown below.
Int PyDict_Next (PyObject * p, Py_ssize_t * ppos, PyObject * * pkey, PyObject * * pvalue)
The meaning of the parameters is as follows.
P: the dictionary to traverse.
Ppos: the location of the entry in the dictionary, which should be initialized to 0.
Pkey: returns the keywords of the dictionary.
Pvalue: returns the value of the dictionary.
Functions corresponding to dictionary operations in Python are provided in Python/C API. For example, the dictionary's item method corresponds to the PyDict_Items () function. The dictionary's keys method corresponds to the PyDict_Keys () function. The dictionary's values method corresponds to the PyDict_Values () function. The function prototypes are shown below.
PyObject* PyDict_Items (PyObject* p)
PyObject* PyDict_Keys (PyObject* p)
PyObject* PyDict_Values (PyObject* p)
The meaning of the parameters is as follows.
P: the dictionary to operate on.
So much for how to embed Python into the CumberCraft + tuple and the application. I hope the above content can be of some help to you and learn more. If you think the article is good, you can share it for more people to see.