Tuple Semantics - Rationale'?

Tim Daneliuk tundra at tundraware.com
Wed Jul 11 15:00:01 EDT 2001


I'm curious about why python was designed to handle the tuple semantics
described below the way it does.  Perhaps one of you language experts
can 'splain it to me.

I have a data structure that looks like this (each of the elements is a
string):

ds = (
      (
       (name-1, descrip-1),
       ( (argA-1, argB-1), ... (argA-n, argB-n) )
      ),

      ...

      (
       (name-n, descrip-n),
       ( (argA-1, argB-1), ... (argA-n, argB-n) )
      ),
     )


One of the tuples of ds has a single arg pair.  That is, it looks
like this:

      (
       (name-n, descrip-n),
       ( (argA-1, argB-1) )
      ),


But, at runtime, python sees is as this:

      (
       (name-n, descrip-n),
       (argA-1, argB-1)
      ),


>From what I've read, to force the data structure to be maintained correctly, 
I have to add a trailing comma to the single arg pair like this:

      )
       (name-n, descrip-n),
       ( (argA-1, argB-1), )
      ),


And that works fine.  But *why* is the trailing comma designed into the
language semantics this way.  I've been scratching my head and cannot come
up with a rationale'.  It seems to me that the explicit use of the parens
should be telling python that I want the second entry in each data
structure to be a *tuple* of 0 or more tuples.

Supposed I did want 0 argument pairs in that tuple, but I wanted to prepare
the way for adding some later.  Would I use:

        (()), (), ((,)) ???

'Just curious...
------------------------------------------------------------------------------
Tim Daneliuk
tundra at tundraware.com



More information about the Python-list mailing list