python gripes survey

Cliff Wells logiplex at
Tue Aug 26 00:35:11 CEST 2003

On Mon, 2003-08-25 at 11:14, Afanasiy wrote:

> I have a bunch, many of them hard to define, but one that I just thought
> of I find strange sometimes is the use of tuples as near-mystery return
> values. I can't help but thinking a C struct with named fields is easier
> to remember than a tuple with fields accessed by integer.

As someone else mentioned, you don't have to access them via an integer,
but your point is still taken.  The return value of time.localtime()
method is a fine example of a mystery tuple.  Fortunately it offers
attribute access as well.

> Sure you can return an associative array, but in my experience the
> preference is to return a tuple. I'll probably get flamed for saying so,
> but this is how I feel and it is unavoidable. Returning a struct in C is
> easier to deal with than returning a near-mystery tuple in Python.

This isn't so much a problem with Python as the programmers using it nor
do I see it as particularly "unavoidable".  If you're returning only a
few (preferably homogenous) items, a tuple makes sense:

x, y, z = getpoint()

More complex return values should probably be in a class instance (which
would seem to be equivalent to returning a C struct in this case):

t = time.localtime(time.time())
print t.tm_hour, t.tm_min, t.tm_sec

makes better sense than:

year, month, mday, hour, min, sec, wday, yday, isdst =


Cliff Wells, Software Engineer
Logiplex Corporation (
(503) 978-6726  (800) 735-0555

More information about the Python-list mailing list