The problem is that sometimes you need to pass any arguments to execute, so I want the function to be empty by default.
Works great for me:
>>> def execute(function = lambda x: x, *args): ... print function, args ... function(args) ... >>> execute() <function <lambda> at 0x01DD1A30> () >>>
I note that your example is trying to use f
in the implementation, and you called the function
parameter. Is it really that simple ?;)
However, you need to understand that Python will not be able to say that you want to skip the default argument if there are no arguments at all, so execute(0)
cannot work because it is trying to treat 0
as a function.
Karl Knechtel
source share