Passing variable-length keyworded arguments list to base class constructor?

Beat Bolli beat.bolli at dware.ch
Fri Jun 30 09:20:14 EDT 2000


Jerome Quelin <jerome.quelin at insalien.org> schrieb in im Newsbeitrag:
962367281.1198008296 at news.libertysurf.fr...
> "Alex Martelli" <alex at magenta.com> wrote:
> >> I was wondering how to pass variable-length keyworded arguments list
> >> to my base-class constructor? Look at the example code below:
> >Doesn't apply work for __init__ just as for any other function?
> Sure it works for __init__ too, I've already tried this approch, but it
doesn't
> work either. In fact, I'm asking the question for __init__ because I run
into
> this problem when calling constructors, but the question is the same for
every
> inherited and overloaded method.
>
> When using the *args syntax, I get an error when calling my constructor
because
> I'm using keywords arguments.
>
> When using the **args syntax, python fetches all keyworded arguments in
_one_
> dictionnary in my constructor, and I want to keep the arguments in
multiple
> key/value pairs (and not flattened in one dictionnary) since the parent
> constructor is waiting for keyworded arguments too.
> If I use the **args syntax and then call the base constructor with:
> Parent.__init__(self, args)
> I got an error since it doesn't wait for a dictionnary as an argument (and
args
> is a dictionnary in this case) but for key=value arguments, with key and
value
> taken from the args dictionnary.
>
> Any idea?

Starting with Python 1.6a[12], you can call Parent.__init__(self, **args).

Beat Bolli
--
dware design & software GmbH
Mattenstrasse 11, CH-2555 Brügg b. Biel
Telefon: +41 (32) 374 27 00, Telefax: +41 (32) 374 27 01
E-Mail: beat.bolli at dware.ch






More information about the Python-list mailing list