How do I pass dict as parameterlist in Python 1.52 ?

Hans Nowak wurmy at earthlink.net
Fri Jan 11 12:55:39 EST 2002


Neal Norwitz wrote:
> 
> maxm wrote:
> >
> > I am writing a product in Zope, and it works fine on Zope 2.4.3 (Python 2.1)
> > where I developed it. Now I am testing it on Zope 2.3.3 (Python 1.5.2) To be
> > backwards compatible, but When I start the server I get an error:
> >
> > manage_addots_UserForm = HTMLFile('manage_addots_UserForm',
> >         globals(), **{'formatTypes':ots_User.formatTypes})
> >                    ^
> >  SyntaxError: invalid syntax

Is there a reason why you can do this:

>>> g(*t)
>>> def g(*args):
	print args
>>> t = (4, 5, 6)
>>> g(*t)
(4, 5, 6)

but not this:

>>> def f(**kwargs):
	print kwargs
>>> d = {1:2, 3:4}
>>> f(**d)
Traceback (most recent call last):
  File "<pyshell#26>", line 1, in ?
    f(**d)
TypeError: f() keywords must be strings

...anyone?

--Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==') 
       # decode for email address ;-)
Site:: http://www.awaretek.com/nowak/



More information about the Python-list mailing list