Parameter passing in python
Christian Tanzer
tanzer at swing.co.at
Thu May 31 12:42:14 EDT 2001
Laura Creighton <lac at cd.chalmers.se> wrote:
> apply(Pmw.ButtonBox.__init__, (self, parent), kw)
>
> Why am I required to do apply to be able to pass the keyword list?
> Some model of Pmw.ButtonBox.__init__(self, args) would be
> more readable.
Python 2.1 (#1, May 2 2001, 18:27:26)
[GCC 2.7.2.1] on linux2
Type "copyright", "credits" or "license" for more information.
>>> def test(* args, ** kw):
... print args,kw
...
>>> test(1,2,3)
(1, 2, 3) {}
>>> test(1,2,3, a = 42, b = 137)
(1, 2, 3) {'b': 137, 'a': 42}
>>> test(1,2,3, a = 42, b = 137, ** {"c" : "x", "d" : "y"})
(1, 2, 3) {'d': 'y', 'b': 137, 'c': 'x', 'a': 42}
>>> test(1,2,3, a = 42, b = 137, * (5,6,7), ** {"c" : "x", "d" : "y"})
(1, 2, 3, 5, 6, 7) {'d': 'y', 'b': 137, 'c': 'x', 'a': 42}
>>>
[Disclaimer: you need Python 2.0 or later for this]
--
Christian Tanzer tanzer at swing.co.at
Glasauergasse 32 Tel: +43 1 876 62 36
A-1130 Vienna, Austria Fax: +43 1 877 66 92
More information about the Python-list
mailing list