Interpolation (was: Keyword calling gotcha ?)
Gordon McMillan
gmcm at hypernet.com
Fri May 28 09:08:45 EDT 1999
Darrell writes:
> Let me show my ignorance a bit.
> def a(**x):
> ... print x
>
> >>> def b(**x):
> ... a(x)
>
> When 'b' calls 'a' it is passing a dictionary while 'a' wants a
> keyword thing that it resolves to a dictionary. Wouldn't be nice if
> the keyword thing could mark the dictionaries it creates. Then just
> pass them though when it sees one if the only other choice was an
> error.
>>> def a(d=None, **kwargs):
... print `d or kwargs`
>>> def b(**kwargs):
... a(kwargs)
>>> b(foo=1, bar=3.3)
{'foo': 1, 'bar': 3.3}
- Gordon
More information about the Python-list
mailing list