Keyword calling gotcha ?
Alex
alex at somewhere.round.here
Tue May 25 15:26:58 EDT 1999
Yeah, I think the problem is that you're passing a dictionary rather
than the same set of arguments to A.__init__.
>>> def keyword_usage_example (**parms):
print parms
keyword_usage_example (parms)
... ... ... >>>
>>> keyword_usage_example (a=1,b=2)
{'b': 2, 'a': 1}
Traceback (innermost last):
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in keyword_usage_example
TypeError: too many arguments; expected 0, got 1
>>>
There's probably a clean way to deal with this, but I don't know it.
Here is a messy way:
def alternative_keyword_usage_example (**parms):
if parms.has_key ('key_word_dictionary'):
parms = parms ['key_word_dictionary']
print parms
alternative_keyword_usage_example (key_word_dictionary = parms)
alternative_keyword_usage_example (a = 1, b = 2)
I think the guys running my newsgroup server will get pissed off if I
show you the output...
See you.
Alex.
More information about the Python-list
mailing list