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

Jerome Quelin jerome.quelin at insalien.org
Fri Jun 30 04:15:47 EDT 2000


Hi all,

I was wondering how to pass variable-length keyworded arguments list
to my base-class constructor? Look at the example code below:

-- File test.py
from Tkinter import *
class F(Frame):
    def __init__(self, **args):
        Frame.__init__(self, args)
        # Here my initialisation stuff
F(bg='blue').mainloop()
-- End of file

When doing this, I got an error in the Tkinter module, because it does
not expect a dictionnary for an argument, but rather a list of
keyworded arguments.

If I write:
    def __init__(self, *args):

it doesn't work because I create the class instance with keyworded
arguments:
    F(bg='blue')

and the * (one star) expects just arguments. Therefore, I must use the
** (double star) construct to fetch a dictionnary.
But how to pass this dictionnary to the parent class constructor?

Thanks,
Jerome
--
jerome.quelin at insalien.org




More information about the Python-list mailing list