Function arguments

Thomas Heller thomas.heller at ion-tof.com
Thu Oct 18 07:13:04 EDT 2001


"Laura Creighton" <lac at strakt.com> wrote...
> class Field(Tkinter.Label):
>     def __init__(self, parent, **kw):
>         # these are the defaults that you will get if you haven't specified
>         defaults={'borderwidth': 1,
>                   'relief' : 'groove',
>                   'width' : 30,
>                   'height' : 2,
>                   'anchor' : 'w',
>                   'text' : 'SPAM SPAM SPAM SPAM',
>                   }
>
>         # overwrite any of the defaults with the dictionary you passed
>         defaults.update(kw)
>
>         Tkinter.Label.__init__(self, parent, **defaults)

What if your 'Field' would accept a named parameter (maybe 'spam=None'),
which would not be required/accepted by 'Label'?
You have to manually remove it from kw, assuming the signature of the
__init__ method would be __init__(self, *args, **kw).

Thomas





More information about the Python-list mailing list