Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85760
| References | <71e8463f-2a60-4fb0-a5b7-0ca7cd3efece@googlegroups.com> <mailman.18794.1424209210.18130.python-list@python.org> <472c49ae-c2ce-4eda-b922-f16613722e31@googlegroups.com> |
|---|---|
| Date | 2015-02-18 11:49 +1100 |
| Subject | Re: What the Pythons docs means by "container" ? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18798.1424220589.18130.python-list@python.org> (permalink) |
On Wed, Feb 18, 2015 at 11:30 AM, candide <c.candide@laposte.net> 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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What the Pythons docs means by "container" ? candide <c.candide@laposte.net> - 2015-02-17 13:21 -0800
Re: What the Pythons docs means by "container" ? Cameron Simpson <cs@zip.com.au> - 2015-02-18 08:39 +1100
Re: What the Pythons docs means by "container" ? candide <c.candide@laposte.net> - 2015-02-17 16:30 -0800
Re: What the Pythons docs means by "container" ? Chris Angelico <rosuav@gmail.com> - 2015-02-18 11:49 +1100
Re: What the Pythons docs means by "container" ? candide <pascal.ortiz@gmail.com> - 2015-02-17 18:14 -0800
Re: What the Pythons docs means by "container" ? MRAB <python@mrabarnett.plus.com> - 2015-02-18 18:04 +0000
Re: What the Pythons docs means by "container" ? Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-18 11:50 -0700
Re: What the Pythons docs means by "container" ? Ethan Furman <ethan@stoneleaf.us> - 2015-02-18 11:43 -0800
Re: What the Pythons docs means by "container" ? Terry Reedy <tjreedy@udel.edu> - 2015-02-18 15:04 -0500
Re: What the Pythons docs means by "container" ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-19 10:03 +1100
Re: What the Pythons docs means by "container" ? Ben Finney <ben+python@benfinney.id.au> - 2015-02-19 11:05 +1100
Re: What the Pythons docs means by "container" ? Chris Angelico <rosuav@gmail.com> - 2015-02-19 11:33 +1100
Re: What the Pythons docs means by "container" ? Terry Reedy <tjreedy@udel.edu> - 2015-02-17 19:54 -0500
Re: What the Pythons docs means by "container" ? perfectican <perfectican@gmail.com> - 2015-02-19 02:59 -0800
Re: What the Pythons docs means by "container" ? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-19 11:20 +0000
Re: What the Pythons docs means by "container" ? Rustom Mody <rustompmody@gmail.com> - 2015-02-20 03:37 -0800
Re: What the Pythons docs means by "container" ? Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-20 11:38 -0700
csiph-web