How do I pass dict as parameterlist in Python 1.52 ?

Hans Nowak wurmy at earthlink.net
Fri Jan 11 13:59:21 EST 2002


On 11 Jan 2002, at 10:25, Cromwell, Jeremy wrote:

> Still true in 2.2, but it's not the error you think it is.
> 
> >>> def f(**kwargs):
> ... 	print kwargs
> ... 	
> >>> d = {1:2, 3:4}
> >>> f(**d)
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> TypeError: f() keywords must be strings
> >>> d = {"one":2, "three":4}
> >>> f(**d)
> {'one': 2, 'three': 4}
> 
> Keywords come in as variable (parameter) names, so they're filtered as such.

Doh!! Yes, you're right-- the keys of the dictionary I tried to pass should of 
course have been strings.

I guess today I should go work in the garden or something instead of 
programming. :-/





More information about the Python-list mailing list