A detailed introduction to the operation of embedding tuples in C/C ++ in Python

Source: Internet
Author: User

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.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.