Keyword passing to superclass written in C

Chris Mellon arkanes at gmail.com
Tue Nov 27 10:58:06 EST 2007


On Nov 27, 2007 6:47 AM, Sven Erik Knop <sknop at perforce.co.uk> 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