[Python] PyTuple_Pack which takes in variable number of arguments

Discussão em 'Python' iniciado por Stack, Agosto 28, 2025.

  1. Stack

    Stack Membro Participativo

    I am on Python 2.6.6 & calling python from c++ .

    How can i write PyTuple_Pack which takes in variable number of arguments .

    I have variable arguments coming which I use a for loop and populate my array . My array has max of 1000 elements but i populate only top no_of_argument elements using

    python_obj = PyString_FromString(arg)


    I DO NOT want to write code like

    if(no_of arg ==1 )
    return PyTuple_Pack(1, python_obj[0]);
    if(no_of arg ==2 )
    return PyTuple_Pack(2, python_obj[0],python_obj[1]);


    I want something like return PyTuple_Pack(no_of_args, followed by my array where pyobjects exist ;

    On net i can see http://docs.python.org/release/2.4.4/whatsnew/node14.html

    A new function, PyTuple_Pack(N, obj1, obj2, ..., objN), constructs tuples from a variable length argument list of Python objects. (Contributed by Raymond Hettinger.)


    However example to write good code using above is not found by my search for which i need your help pls..

    Continue reading...

Compartilhe esta Página