0

in plain python (2.7) one can write variadic function like so:

>> def myfunc(a, b, *args):
    print a,b,args

>> params = (1,2,"3", "abc")

>> myfunc(*params)
# Will print "1 2 ('3', 'abc')"

>> myfunc(params)
# Will fail with 'myfunc() takes at least 2 arguments (1 given)'

When writing a Python extension in C, I can pass a tuple of PyObjects (like params in the example) easily, but how can I pass params with the *-operator with function such as PyObject_CallMethodObjArgs and the likes.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Perfect99
  • 9
  • 2
  • You mean you want to know how to pass in `params` as separate arguments from C code, like `*` would? Does [Passing variable number of arguments around](//stackoverflow.com/q/205529) apply here? – Martijn Pieters May 03 '17 at 11:36
  • [`PyObject_Call`](https://docs.python.org/3/c-api/object.html#c.PyObject_Call)? – DavidW May 03 '17 at 14:40
  • Please clarify how you want to call the function. Do you just want the equivalent of `myfunc(*params)`? – MSeifert May 07 '17 at 14:57

0 Answers0