Keyword passing to superclass written in C

Chris Mellon arkanes at
Tue Nov 27 16:58:06 CET 2007

On Nov 27, 2007 6:47 AM, Sven Erik Knop <sknop at> wrote:
> Hi
> I am getting slightly frustrated and wonder if you can help me.
> Consider a Python class Foo implemented in C++. I have declared an
> initialization method like this
> static int
> Foo_init(P4Adapter *self, PyObject *args, PyObject *kwds)
> {
> }
> and I am subclassing Foo in Python, which works fine in principle,
> except for passing keywords.
> Here is the subclass:
> class Bar(Foo):
>   def __init__(self, *args, **kwlist):
>      Foo.__init__(self, args, kwlist)

This passes the args tuple and the kw dict as 2 regular arguments. You
need to expand them in the second call if you want them to be passed
as args and kwargs -
Foo.__init__(self, *args, **kwargs)

More information about the Python-list mailing list