except clause syntax question
Charles Yeomans
charles at declareSub.com
Tue Jan 31 11:23:04 EST 2012
On Jan 31, 2012, at 9:51 AM, Steven D'Aprano wrote:
> On Tue, 31 Jan 2012 08:57:31 -0500, Charles Yeomans wrote:
>
>> I don't think of a tuple as a container, and I don't think it a
>> misunderstanding on my part to think this.
>
> Well, it is a misunderstanding, because tuples ARE containers. You might
> as well say "I don't think of boxes as containers". What exactly are they
> if not containers?
Tuple is a heterogenous datatype that allows one to define objects ad hoc. That is to say, a tuple represents a single thing distinct from its components. For example, suppose you need to represent a location in text by line number and offset within a line. A tuple object makes it easy to do so without writing a class having no methods other than a constructor. Here, the components, a line number and an offset, define a new object distinct from the pieces.
One can certainly view a tuple as a list, just as one can view a string as a list of characters, and sometimes that's useful; the Python dictum "there should only be one way to do it" doesn't imply that there is only one way to think of it.
Nor am I the only person who sees such a distinction between tuple and list.
Charles Yeomans
More information about the Python-list
mailing list