[Python-ideas] values in vs. values out

Rob Cliffe rob.cliffe at btinternet.com
Thu Jan 13 15:56:13 CET 2011


To deal with specifically adding a new value to a returned tuple, you 
could write your function calls to truncate the tuple to the expected 
length, e.g.

def myfunc():
     ...
     return (result1, result2, newresult)

x,y = myfunc()[2]

x,y,z = myfunc()[3]

So you would have to change all the relevant function calls, but only once.
More generally, perhaps you could return a dictionary.  Although this 
makes the function calls a bit more awkward:

results = myfunc()
x, y = results['result1'], results['result2']

Best wishes
Rob Cliffe

On 13/01/2011 14:30, Luc Goossens wrote:
> Hi all,
>
> There's a striking asymmetry between the wonderful flexibility in 
> passing values into functions (positional args, keyword args, default 
> values, *args, **kwargs, ...) and the limited options for processing 
> the return values (assignment).
> Hence, whenever I upgrade a function with a new keyword arg and a 
> default value, I do not have to change any of the existing calls, 
> whereas whenever I add a new element to its output tuple, I find 
> myself chasing all existing code to upgrade the corresponding 
> assignments with an additional (unused) variable.
> So I was wondering whether this was ever discussed before (and 
> recorded) inside the Python community.
> (naively what seems to be missing is the ability to use the assignment 
> machinery that binds functions' formal params to the given actual 
> param list also in the context of a return value assignment)
>
> cheers,
> Luc
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



More information about the Python-ideas mailing list