[Tutor] tuple sorting

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Thu, 6 Jun 2002 07:33:29 -0700 (PDT)


> >>> a = ((4,1,8), (9,2,5),(3,6,9))
> >>> b = list(a)
> >>> b.sort()
> >>> a = tuple(b)
> >>> print a
> ((3, 6, 9), (4, 1, 8), (9, 2, 5))
>
> I guess I found a very trivial typo in the distribution. Is this worth
> reporting?

Yes.  Good eyes.  *grin*


The docstring was buggy, but this has been fixed in Python 2.2:

###
Python 2.2.1 (#1, Apr 13 2002, 13:15:33)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print tuple.__doc__
tuple() -> an empty tuple
tuple(sequence) -> tuple initialized from sequence's items

If the argument is a tuple, the return value is the same object.
###



> This gave me the ambition to rummage in the innards of python. I know
> there is a doc string somewhere in the source but after using windows
> find tool looking in C:\Python21 for the text I couldn't find the
> physical file where it's located.

In Python 2.2, it should be located in the Objects/tupleobject.c file; the
docstring is held in a variable called 'tuple_doc'.

I don't have a copy of the Python 2.1 sources handy at the moment, but
looking at Sourceforge, I think I've found it in 'Python/bltinmodule.c':

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/python/python/dist/src/Python/bltinmodule.c?rev=2.197.2.1&only_with_tag=r213


The tuple() function moved between 2.1 to 2.2 as a side effect of the
unification between types and classes:

    http://www.python.org/2.2/descrintro.html

so that explains why it moved from 'bltinmodule.c' to 'tupleobject.c'.


Hope this helps!