[Python-ideas] values in vs. values out
Steven D'Aprano
steve at pearwood.info
Thu Jan 13 16:27:19 CET 2011
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).
You're not limited to returning tuples. You could return an object with
named attributes, or a namedtuple, or even just a dict. There's
precedence in the standard library, for example, os.stat.
Except in the case of tuple unpacking, this does mean that assigning the
result of the function call is a two stage procedure:
t = func(x, y, z)
a, b, c = t.spam, t.ham, t.cheese
but it does give you flexibility in adding new return fields without
having to update function calls that don't use the new fields.
--
Steven
More information about the Python-ideas
mailing list