In python is it possible to have the above code without raising an exception ?
def myfunc():
pass
# TypeError myfunc() takes no arguments (1 given)
myfunc('param')
Usually in php in some circumstances I launch a function without parameters and then retrieve the parameters inside the function.
In practice I don’t want to declare arguments in myfunc and then passing some arguments to it. The only one solution I found is myfunc(*arg). Are there any other methods ?
And to actually answer the question: no, I do not believe there are other ways.
The main reason is pretty simple:
C python is stack based. A function that doesn’t require parameters will not have space allocated for it on the stack ((see comments)myFunc, instead, has them in position 0 and 1).An additional point is, how would you access the parameters otherwise?