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

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


On Wed, 17 Nov 2004 19:46:02 -0200, Carlos Ribeiro <carribeiro at gmail.com> 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
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303770

* Tuples with named elements -- Andrew Durdin
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303439

* super tuples -- Gonçalo Rodrigues
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/218485

* Tuples with named elements - using metaclasses -- Andrew Durdin
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303481

* Just van Rossum's NamedTuple
http://just.letterror.com/ltrwiki/JustVanRossum_2fNamedTuple

* Christos Georgiou -- an old reference to a similar problem (named
structs) on Google Groups
http://groups.google.com/groups?selm=735o0vk4uciifl692o51fk9om87o37bo6k%404ax.com

* Another reference to the same code posted above, from the author's website
http://www.sil-tec.gr/~tzot/python/TupleStruct.py

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
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com



More information about the Python-list mailing list