Javascript has a poorly constructed but convenient “arguments” variable inside every function, such that you can pass arguments through a function like so:
function foo(a, b, c) {
return bar.apply(this, arguments);
}
function bar(a, b, c) {
return [a, b, c];
}
foo(2, 3, 5); // returns [2, 3, 5]
Is there an easy way to do a similar thing in Python?
Yeah, this is what I should have said.
You don’t need to declare the function with (a,b,c). bar(…) will get whatever foo(…) gets.
My other crummier answer is below:
I was so close to answering “No, it can’t easily be done” but with a few extra lines, I think it can.
@cbrauchli great idea using locals(), but since locals() also returns local variables, if we do
we’ll be passing an unwanted 4th argument, n, to bar(a,b,c) and we’ll get an error. To solve this, you’d want to do something like arguments = locals() in the very first line i.e.