我需要能够获取传递给我的函数 make_choice 的所有参数。但在第 25 行(requesterverb)我收到运行时错误:
requester[verb](kwargs)
TypeError: doPUT() takes exactly 0 arguments (1 given)
我究竟做错了什么?
这是我的代码:
#switch using dictionary
def make_choice(verb, **kwargs):
def doGET(**kwargs):
print "Doing GET"
for key in kwargs:
print "another keyword arg: %s: %s" % (key, kwargs[key])
def doPUT(**kwargs):
print "Doing PUT"
for key in kwargs:
print "another keyword arg: %s: %s" % (key, kwargs[key])
def doDELETE(**kwargs):
print "Doing DELETE"
def doPOST(**kwargs):
print "Doing POST"
def doPATCH(**kwargs):
print "Doing PATCH"
requester = { 'GET': doGET, 'PUT': doPUT }
requester[verb](kwargs)
make_choice(verb='PUT',param1='param1',param2='param2',param3='param3')
print "done"