[EMAIL PROTECTED] wrote: > Ok, thx > But can I somehow determing how many outputs does caller func require? > for example: > MATLAB: > function [objFunVal firstDerive secondDerive] = simpleObjFun(x) > objFunVal = x^3; > if nargout>1 > firstDerive = 3*x^2; > end > if nargout>2 > secondDerive = 6*x; > end > > So if caller wants only > [objFunVal firstDerive] = simpleObjFun(15) > than 2nd derivatives don't must to be calculated with wasting cputime. > Is something like that in Python?
Return an object with each of the results objFunVal, firstDerive, and secondDerive as attributes (or a dictionary). Use keyword arguments to inform the function of which ancillary computations it needs to perform. If at all possible, don't change the number of return values. It's annoying to deal with such an API. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list