Reputation: 1143
I'm confused about why this error is occurring:
TypeError: func1() takes exactly 0 arguments (1 given)
The code is as follows:
def func1(**kwargs):
if kwargs['dog'] != 2:
return False
return True
def func2(**kwargs):
if kwargs['cat'] != 3:
return False
return True
def func3(*listOfFuncs, **extraArgs):
for func in listOfFuncs:
if func(extraArgs) == False:
print 'break'
break
print 'continue'
continue
func3(func1, func2, dog=2, cat=1)
I'm trying to pass function names as arguments to func3. I also want to pass both 'cat' and 'dog' keyword arguments to both func1 and func2 when they are called in fun3 but only use a single keyword argument in each of those functions?
Any help would be appreciated
Upvotes: 1
Views: 116
Reputation: 589
You have to pass the **kwargs args at the time of function call.
I have just reviewed your code. Please try following
def func1(**kwargs):
if kwargs['dog'] != 2:
return False
return True
def func2(**kwargs):
if kwargs['cat'] != 3:
return False
return True
def func3(*listOfFuncs, **extraArgs):
print
for func in listOfFuncs:
if func(**extraArgs) == False:
print 'break'
break
print 'continue'
continue
func3(func1, func2, dog=2, cat=1)
Output :
continue
break
Upvotes: 2