Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'distinct': 0.05; 'suppose': 0.05; 'components.': 0.07; 'defines': 0.07; 'distinction': 0.07; 'imply': 0.07; 'python': 0.08; 'immutable': 0.09; 'mutable': 0.09; 'tuple': 0.09; 'tuple.': 0.09; 'am,': 0.12; 'things.': 0.12; 'cc:addr:python-list': 0.15; 'examples': 0.15; 'arbitrarily': 0.16; 'constructor.': 0.16; 'container,': 0.16; 'containers': 0.16; 'identities': 0.16; 'implied.': 0.16; 'mouth.': 0.16; 'mutability': 0.16; 'objects;': 0.16; 'offset,': 0.16; 'quote.': 0.16; 'sees': 0.16; 'subject:syntax': 0.16; 'tuple)': 0.16; 'tuples,': 0.16; 'subject:question': 0.16; 'wrote:': 0.16; 'language': 0.17; '>>>': 0.18; 'say,': 0.19; 'jan': 0.19; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'statement': 0.23; 'objects,': 0.23; 'string': 0.24; 'object,': 0.24; 'cc:2**0': 0.25; '(like': 0.25; 'lists': 0.28; 'message- id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.29; 'class': 0.29; 'characters,': 0.30; 'components,': 0.30; "it'd": 0.30; 'tuples': 0.30; 'types.': 0.30; "didn't": 0.30; 'values': 0.32; 'certainly': 0.32; 'represents': 0.32; 'value.': 0.32; 'changes': 0.32; 'objects': 0.32; 'tue,': 0.32; 'list': 0.32; "isn't": 0.32; 'it.': 0.33; 'object': 0.33; 'there': 0.33; 'this.': 0.33; 'field,': 0.34; 'list.': 0.34; 'rather': 0.34; 'keys': 0.34; 'matter,': 0.34; 'things': 0.35; 'received:209.85.160.46': 0.35; 'received:mail-pw0-f46.google.com': 0.35; 'external': 0.35; 'received:209.85.160': 0.35; 'however,': 0.35; 'example,': 0.36; 'offset': 0.36; 'reference': 0.37; 'represent': 0.37; 'list,': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'cases,': 0.38; 'references': 0.38; 'steven': 0.38; 'used,': 0.38; 'allows': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'useful': 0.38; 'put': 0.38; 'think': 0.38; 'sometimes': 0.38; 'should': 0.38; 'talk': 0.39; 'except': 0.39; 'define': 0.39; 'called': 0.39; 'received:209': 0.39; 'subject:: ': 0.39; 'might': 0.40; 'most': 0.60; 'your': 0.61; '8bit%:23': 0.62; '31,': 0.64; 'view': 0.64; 'grab': 0.66; 'charles': 0.67; 'suited': 0.73; '"there': 0.84; '-0500,': 0.84; '2012,': 0.84; 'ad-hoc': 0.84; 'it"': 0.84; 'quote:': 0.84; 'beside': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=Kpcqq1ag6qiRqxI4OzJjoaSmpLet+W3UerAphl9+G+4=; b=qrA/tKJ+PtYeCpHD42/KFxHHbzacbHrDhECOSRFT1odJDQxN5xBUcNqKejXxXI+C7P N7QRNh81fH5X/dP+KwA234LaptRE2oPc2jOfBIrXgDI8Sg933j/9EyrnA8u10cJqO4gW py2cCcW6+zQFT9drzOhyOnfrNYU/wAgkhXapU= MIME-Version: 1.0 In-Reply-To: <440642C3-B9CD-4BC7-AF57-4013238C2C5C@declareSub.com> References: <4f272f1f$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f27ffd8$0$29989$c3e8da3$5496439d@news.astraweb.com> <440642C3-B9CD-4BC7-AF57-4013238C2C5C@declareSub.com> From: Devin Jeanpierre Date: Tue, 31 Jan 2012 11:38:44 -0500 Subject: Re: except clause syntax question To: Charles Yeomans Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328027967 news.xs4all.nl 6942 [2001:888:2000:d::a6]:38842 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19648 On Tue, Jan 31, 2012 at 11:23 AM, Charles Yeomans wrote: > > 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 the= y >> 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 compo= nents. =C2=A0For example, suppose you need to represent a location in text = by line number and offset within a line. =C2=A0A tuple object makes it easy= to do so without writing a class having no methods other than a constructo= r. =C2=A0Here, the components, a line number and an offset, define a new ob= ject distinct from the pieces. > > One can certainly view a tuple as a list, just as one can view a string a= s a list of characters, and sometimes that's useful; the Python dictum "the= re should only be one way to do it" doesn't imply that there is only one wa= y to think of it. > > Nor am I the only person who sees such a distinction between tuple and li= st. Perhaps it'd be useful to look at how the Python language reference defines containers? Quote: Some objects contain references to other objects; these are called containers. Examples of containers are tuples, lists and dictionaries. The references are part of a container=E2=80=99s value. In most cases, when= we talk about the value of a container, we imply the values, not the identities of the contained objects; however, when we talk about the mutability of a container, only the identities of the immediately contained objects are implied. So, if an immutable container (like a tuple) contains a reference to a mutable object, its value changes if that mutable object is changed. End quote. (Offtopic: How do I do an external block quote appropriately in an email?) Tuples are most certainly containers, precisely _because_ they're an ad-hoc way to define objects, where the only purpose of the object is to contain the values inside the tuple. But these are just words and it's beside the point. We should talk of things as if the word "container" didn't matter, because I don't think that's what you meant, but neither do I want to put words in your mouth. My interpretation is that you see tuples as an object where you can get meaningfully things by field, rather than just grab arbitrarily from a bag of things. This isn't the only way they are used, see the except statement (hee) and their use as keys in dictionaries. But it is true that their immutable length makes them very well suited to the task of representing product types. -- Devin