Skip to content

Instantly share code, notes, and snippets.

@tmf16
Created October 20, 2012 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmf16/3921711 to your computer and use it in GitHub Desktop.
Save tmf16/3921711 to your computer and use it in GitHub Desktop.
可変長引数にdictを渡す
>>> def func_dict(**argv):
... print 'dict ----'
... print argv
...
>>>
>>> d = {'a': 1, 'b': True, 'c': u'ほげ'}
>>>
>>> func_dict(d)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: func_dict() takes exactly 0 arguments (1 given)
>>>
>>> func_dict(**d)
dict ----
{'a': 1, 'c': u'\u307b\u3052', 'b': True}
>>>
>>> func_dict(test=d)
dict ----
{'test': {'a': 1, 'c': u'\u307b\u3052', 'b': True}}
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment