I've found myself trying to interface a custom class with builtin functions, and I've encoutered a situation I could only solve with eval, I'd like a "cleaner" way.
Basically, the builtin function is defined as varargout=blabla(varargin)
I defined an overriden function in the custom class, as varargout=blabla(varargin)
. The function looks like:
function varargout=blabla(varargin)
varargout=blabla(function_of_varargin)
end
The function of varargin
transforms it from the custom class to the builtin clas.
But it doesn't work as-is: Basically when the builtin function is called inside the overriden function, it sees only one output parameter (varargout
), even if the custom overriden function is called with more than one output parameter.
I solved it by basically calling this :
[varargout{1},varargout{2},...,varargout{nargout}]=blabla(function_of_varargin)
Constructing the LHS with a loop and eval-ing.
For a function, the input is called the independent variable , and the output is called the dependent variable .
To call a function with a variable number of arguments, simply specify any number of arguments in the function call. An example is the printf function from the C run-time library. The function call must include one argument for each type name declared in the parameter list or the list of argument types.
Yes. You can use *args as a non-keyword argument. You will then be able to pass any number of arguments. As you can see, Python will unpack the arguments as a single tuple with all the arguments.
To return a value from a function, you must include a return statement, followed by the value to be returned, before the function's end statement. If you do not include a return statement or if you do not specify a value after the keyword return, the value returned by the function is unpredictable.
Have you tried this:
[varargout{1:nargout}] = blabla(varargin{:})
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With