473,508 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python C/API - *arg,**kwds variable argumnents

I am writing a C extension with python 2.3.5 and need constructs
similar to python
func(*args, **kwds)
What's a neat way to do that?
I found pyrex has a __Pyx_GetStarArgs -
is there something I'm missing from the regular C/API maybe using one
of the PyArg_Parse.. calls ?

Thanks,
M.

Dec 14 '05 #1
6 1566
md*****@gmail.com wrote:
I am writing a C extension with python 2.3.5 and need constructs
similar to python
func(*args, **kwds)
What's a neat way to do that?
I found pyrex has a __Pyx_GetStarArgs -
is there something I'm missing from the regular C/API maybe using one
of the PyArg_Parse.. calls ?

Thanks,
M.


It looks like the PyArg_ParseTupleAndKeywords API call is what you are
looking for. Documentation is

http://python.org/doc/2.4.2/ext/pars...dKeywords.html
Dec 14 '05 #2
I saw that in 2.4, although it's not clear how I can make it work. the
argument char *format and char *keywords[] are fixed there. Does anyone
have a working example?
I'm just wondering if there are plans or already an API/C in python
core similar to __Pyx_GetStarArgs. It seems like a very usefull and
common thing for extensions writer.
pyrex actually does a very neat job, looking at its output is really
instructive. How widespread is this solution? I started my extensions
long ago before realizing such solution existed, and rather stick to a
regular python API, understood this is what pyrex generates -

M.
Raymond L. Buvel wrote:
md*****@gmail.com wrote:
I am writing a C extension with python 2.3.5 and need constructs
similar to python
func(*args, **kwds)
What's a neat way to do that?
I found pyrex has a __Pyx_GetStarArgs -
is there something I'm missing from the regular C/API maybe using one
of the PyArg_Parse.. calls ?

Thanks,
M.


It looks like the PyArg_ParseTupleAndKeywords API call is what you are
looking for. Documentation is

http://python.org/doc/2.4.2/ext/pars...dKeywords.html


Dec 14 '05 #3
essentially I already use PyArg_ParseTupleAndKeywords, but that seems
to emulate fixed arg list definitions like -
func (x,y,t=0,u=1)

Dec 14 '05 #4
md*****@gmail.com wrote:
I am writing a C extension with python 2.3.5 and need constructs
similar to python
func(*args, **kwds)
What's a neat way to do that?


static PyObject*
myfunc(PyObject* self, PyObject* args, PyObject* kw)
{
... args is a tuple, kw is a dictionary ...
}

static PyMethodDef _functions[] = {
{"myfunc", (PyCFunction) myfunc, METH_VARARGS|METH_KEYWORDS},
{NULL, NULL}
};

</F>

Dec 14 '05 #5
On Wed, 2005-12-14 at 12:00, md*****@gmail.com wrote:
essentially I already use PyArg_ParseTupleAndKeywords, but that seems
to emulate fixed arg list definitions like -
func (x,y,t=0,u=1)


It's unclear what you are actually trying to accomplish. My guess is
that you want to implement a function/method that takes any number of
arbitrarily named keyword arguments. If that is the case, you can simply
use the dictionary that is passed to your C function as the third
argument.

Hope this helps,

Carsten.

Dec 14 '05 #6

thanks, I get it now.

Dec 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2942
by: Raymond Hettinger | last post by:
Here are four more mini-mysteries for your amusement and edification. In this episode, the program output is not shown. Your goal is to predict the output and, if anything mysterious occurs,...
699
33326
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
10
3034
by: Berthold Hoellmann | last post by:
Hello, When I use ./configure --with-thread --with-fpectl --with-signal-module \ --with-pymalloc --enable-shared --with-cxx=g++ make test on 2.3.3 I get
23
1868
by: Simon Wittber | last post by:
For the first time, I have been bitten by Python. The below code produces the results: False True when I initially expected the results: False False It took me a while to work out that...
76
3686
by: Nick Coghlan | last post by:
GvR has commented that he want to get rid of the lambda keyword for Python 3.0. Getting rid of lambda seems like a worthy goal, but I'd prefer to see it dropped in favour of a different syntax,...
12
1493
by: could ildg | last post by:
I have learned python for over a month. I heard that it was very easy to learn, but when I tried to know OO of python, I found it really weird, some expressions seem very hard to understand, and I...
6
1382
by: Michele Simionato | last post by:
could ildg wrote: > I think decorator is a function which return a function, is this right? > e.g. The decorator below if from http://www.python.org/peps/pep-0318.html#id1. > > def...
8
3016
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
5
6725
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.