Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!newsfeed.xs4all.nl!newsfeed1a.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'received:209.85.223': 0.03; 'definitions': 0.07; 'string': 0.09; 'definition,': 0.09; 'function,': 0.09; 'here?': 0.09; 'namespace': 0.09; 'objects,': 0.09; 'used.': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'itself.': 0.14; '"is': 0.16; 'containers': 0.16; 'exceptions,': 0.16; 'foot': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'function),': 0.16; 'itself,': 0.16; 'latter,': 0.16; 'tuple': 0.16; 'tuples,': 0.16; 'exception': 0.16; 'language': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'aspect': 0.24; 'instance,': 0.24; 'integer': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'references': 0.26; '(for': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; '[1]': 0.29; 'am,': 0.29; 'thus': 0.29; 'involving': 0.30; 'message- id:@mail.gmail.com': 0.30; '(which': 0.31; 'code': 0.31; 'too.': 0.31; 'container': 0.31; 'shoot': 0.31; 'stuff': 0.32; 'quite': 0.32; 'entirely': 0.33; 'used,': 0.33; 'subject:the': 0.34; 'could': 0.34; "can't": 0.35; 'received:209.85': 0.35; 'something': 0.35; 'definition': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'object,': 0.36; 'useful': 0.36; 'possible': 0.36; 'so,': 0.37; 'list': 0.37; 'received:209': 0.37; 'expected': 0.38; 'list,': 0.38; 'aspects': 0.39; 'itself': 0.39; 'even': 0.60; 'most': 0.60; "you're": 0.61; 'first': 0.61; 'term': 0.63; 'such': 0.63; 'skip:n 10': 0.64; 'different': 0.65; 'between': 0.67; 'real-world': 0.68; 'useful.': 0.68; 'results': 0.69; 'containing': 0.69; 'yourself': 0.78; '2015': 0.84; 'distinguish': 0.84; 'etc,': 0.84; 'sets,': 0.84; 'substrings': 0.84; 'technically': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=fzUlGx7jn05GkBmVAfSo7U8Xd2T3cToS2eXCb56zVBg=; b=c1YcanWf8f6EyQoxT02bBU9WHJRNQThaBVaX+ZSFSzAtDGwOdejWBypdtE9coODmY6 Wm7uVQY87miwfeVwOUcTxZENa4gaJ0oCNmoMueae3qAniSdD33qnAMOrAnAXTEW2h4Nz 9sUDJXOsCoOE8bWfSJofeFY7y6OucAS7TScaSpnirGxUgP2DSfEVZWu6oNNU/SGnXpuR ptZGwRy0gnwIa8P4u+5pXxxUkSbRnmq4pr9xJ2krtxsecZpHseDtoKucPY287Vn6TC86 NHqmVLysJcRQNxddKmHdIZKg7XSP7HP7NxPJmfUio70ZqzFj9lwxami5EayekjOIAOr8 ayPA== MIME-Version: 1.0 X-Received: by 10.50.61.238 with SMTP id t14mr31871620igr.34.1424220586752; Tue, 17 Feb 2015 16:49:46 -0800 (PST) In-Reply-To: <472c49ae-c2ce-4eda-b922-f16613722e31@googlegroups.com> References: <71e8463f-2a60-4fb0-a5b7-0ca7cd3efece@googlegroups.com> <472c49ae-c2ce-4eda-b922-f16613722e31@googlegroups.com> Date: Wed, 18 Feb 2015 11:49:46 +1100 Subject: Re: What the Pythons docs means by "container" ? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424220590 news.xs4all.nl 2861 [2001:888:2000:d::a6]:35641 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85760 On Wed, Feb 18, 2015 at 11:30 AM, candide wrote: > Python Language Referenceb (PLR) is expected to give formal and acurate definition, not "descriptive term to talk about things". In a lot of ways, technically accurate definitions can be useless, where sloppy but descriptive terms are useful. For instance, we can distinguish between an integer (doesn't contain things) and a list (does contain things), and then categorize sets, tuples, and SimpleNamespace()s with the latter, and exceptions, strings, and functions with the former. But technically, an exception has a reference to something else (a traceback), and could thus be said to contain it, and a function always has a reference to its global namespace (which itself contains that function), etc, so any specific and formal definition is likely to be quite useless. Also, a string can be said to "contain" a whole lot of substrings - "bcd" in "abcde" is True - even though those substrings don't actually have to exist as objects, so it's impossible for the string to retain references to those substrings. Even worse, a string always contains *itself*, which makes a definition based on the 'in' operator conflict entirely with a definition based on a real-world analogy involving a box with stuff in it. So, what's a container? It's a thing that you put other objects into. That's all the definition you really need, most of the time. If you want a better definition, you first need to ask yourself: What aspect of "containerness" matters here? Why do you need to distinguish container from non-container? If you want to know whether the 'in' operator can be used, then ask whether the 'in' operator can be used. If you want to know whether it's possible for this object to be part of a reference cycle, ask whether it's possible for this object to be part of a reference cycle. If you want to know whether this is a useful way to return multiple results from a function, then ... you get the idea. They're all very different aspects of containers, and not all containers have all those aspects. (For instance, a tuple can't [1] have a reference to itself. You can't get a reference cycle without having some other type of object, such as a list, involved.) "Is this a container?" isn't often a useful question to ask. ChrisA [1] You can use C code to create a tuple containing itself, but in C, you're most welcome to shoot yourself in the foot in other ways, too.