This question should be really easy to answer, however I didn't find anything/don't know how to search.
def testcall(function, argument):
function(*argument)
testcall(print, "test")
# output:
t e s t
why t e s t
and not test
?
This question should be really easy to answer, however I didn't find anything/don't know how to search.
def testcall(function, argument):
function(*argument)
testcall(print, "test")
# output:
t e s t
why t e s t
and not test
?
You are using the splat syntax (*argument
) to break up argument
into individual characters. Then, you are passing these characters to print
. It is no different than doing:
>>> print('t', 'e', 's', 't')
t e s t
>>>
Remove the *
to fix the problem:
>>> def testcall(function, argument):
... function(argument)
...
>>> testcall(print, "test")
test
>>>
Your splats are asymmetric. It should be:
def testcall(function, *argument):
function(*argument)
In general, if you want your function to behave like another function, it should accept a splat and send a splat. This answer explains the general case