Super Tuples
Colin J. Williams
cjw at connection.com
Tue Dec 28 16:49:22 EST 1999
Paul Prescod wrote:
> I propose that in Python 1.6 tuples be given the demonstrated features:
>
> >>> time = (hour=24, minute=00, second=00 )
>
> >>> print time.hour
> 24
>
> >>> hr, min, sec = time
> >>> print hr, min, sec
> (24, 00, 00 )
> >>> min, sec, hr = time
> >>> print min, sec, hr
> (24, 00, 00 )
>
> (this last just demonstrates that tuples continue to work the way they
> always have. There is no magic about looking at the names of
> assignments)
This seems to be the PL1/Pascal record idea. I like it.
Could one use this in a multi-level manner?
eg.
>>> transaction= (addressee= 'bloggs at dot.com', contentType= 'HTML',
... dispatchedAt= time) # time as
defined above
>>> print transaction.dispatchedAt.hour
24
>
>
> This proposal has the following benefits:
>
> * it makes a nice syntax for a 1-item tuple :)
> * it makes a nice syntax for non pre-declared struct-like things
> * it aligns better with the mathematical notion of tuple
> * the element referencing syntax is much clearer
> * names are easier to remember and less error prone than indexes.
> * it is still easy to rip them apart
>
> This proposal may lead some to consider the unification of tuples and
> object instances, which is also a discussion worth having.
>
> OpiniX-Mozilla-Status: 0009ould apply a patch to this effect?
>
> Paul Prescod
Colin W.
More information about the Python-list
mailing list