Are multiple return values really harmful? (Re: determining the number of output arguments)

Carlos Ribeiro carribeiro at
Wed Nov 17 23:18:34 CET 2004

On Wed, 17 Nov 2004 19:46:02 -0200, Carlos Ribeiro <carribeiro at> wrote:
> The return of this function would be a 'named tuple'. It could be
> treated like a sequence (using __getitem__), or like a dict (using
> __getattr__). This way, we could have the best of both worlds; the
> simplicity of tuples and the convenience of named attribute access.

Well.. I think I should have googled for it *before* hitting the send button :-)

There are a few recipes in the Python Cookbook to deal with named
tuples. I've collected some pointers for those who may be interested
into this topic:

* Tuples with Named Elements via Spawning -- Derrick Wallace

* Tuples with named elements -- Andrew Durdin

* super tuples -- Gonçalo Rodrigues

* Tuples with named elements - using metaclasses -- Andrew Durdin

* Just van Rossum's NamedTuple

* Christos Georgiou -- an old reference to a similar problem (named
structs) on Google Groups

* Another reference to the same code posted above, from the author's website

One of the reasons I became interested on this is related to my
previous problems with 'unordered' dicts in some contexts, specially
when implementing some metaclass tricks. We've had some discussion
here about two months ago, and  one of the comments was that it would
be useful if the locals() dict used in a class definition stored order
information. I see some parallels between the two problems (ordered
dicts and named tuples). The fact that named tuple are immutable by
definition should help in this case.

Carlos Ribeiro
Consultoria em Projetos
mail: carribeiro at
mail: carribeiro at

More information about the Python-list mailing list