Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85754
| Path | csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <cameron@cskk.homeip.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'falls': 0.09; 'fashion.': 0.09; 'indeed,': 0.09; 'integers': 0.09; 'mining': 0.09; 'themselves,': 0.09; 'python': 0.11; '"in"': 0.16; '>the': 0.16; 'bounds': 0.16; 'collections': 0.16; 'container.': 0.16; 'containers': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'helps.': 0.16; 'invokes': 0.16; 'iterable': 0.16; 'iterables': 0.16; 'iterating': 0.16; 'iteration': 0.16; 'iteration,': 0.16; 'iteration.': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'method;': 0.16; 'objects.': 0.16; 'objects;': 0.16; 'qualifying': 0.16; 'simpson': 0.16; 'skip:> 20': 0.16; 'wrote:': 0.18; 'module': 0.19; 'things.': 0.19; 'typing': 0.19; 'not,': 0.20; 'memory': 0.22; '(in': 0.22; 'manual': 0.22; 'header:User- Agent:1': 0.23; 'him.': 0.24; 'lets': 0.24; 'cheers,': 0.24; 'references': 0.26; 'header:In-Reply-To:1': 0.27; 'membership': 0.31; 'usually': 0.31; 'container': 0.31; 'jean': 0.31; 'file': 0.32; 'class': 0.32; 'compatible': 0.32; 'url:python': 0.33; 'not.': 0.33; 'subject:the': 0.34; 'basic': 0.35; 'knows': 0.35; 'objects': 0.35; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'explains': 0.36; 'object,': 0.36; 'useful': 0.36; 'charset:us- ascii': 0.36; 'url:org': 0.36; 'so,': 0.37; 'list.': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'skip:. 10': 0.39; 'use.': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'even': 0.60; 'most': 0.60; 'no.': 0.61; 'url:3': 0.61; 'range': 0.61; 'back': 0.62; 'content-disposition:inline': 0.62; 'term': 0.63; 'great': 0.65; 'effectively': 0.66; 'side': 0.67; 'yes': 0.68; 'frequently': 0.68; 'reads': 0.68; 'realized': 0.68; 'containing': 0.69; 'hoping': 0.75; 'abc': 0.84; 'footprint': 0.84; 'received:192.168.15': 0.84; 'url:datamodel': 0.84; 'url:html#object': 0.84; 'url:reference': 0.84; 'thing,': 0.91 |
| Date | Wed, 18 Feb 2015 08:39:54 +1100 |
| From | Cameron Simpson <cs@zip.com.au> |
| To | python-list@python.org |
| Subject | Re: What the Pythons docs means by "container" ? |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii; format=flowed |
| Content-Disposition | inline |
| In-Reply-To | <71e8463f-2a60-4fb0-a5b7-0ca7cd3efece@googlegroups.com> |
| User-Agent | Mutt/1.5.23 (2014-03-12) |
| References | <71e8463f-2a60-4fb0-a5b7-0ca7cd3efece@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18794.1424209210.18130.python-list@python.org> (permalink) |
| Lines | 52 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1424209210 news.xs4all.nl 2919 [2001:888:2000:d::a6]:46199 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:85754 |
Show key headers only | View raw
On 17Feb2015 13:21, candide <c.candide@laposte.net> wrote: >Official Python documentation very frequently invokes a mysterious *container* data structure. The PLR manual explains : >-------------------------- >Some objects contain references to other objects; these are called containers. >-------------------------- And this is the basic thing, as you understand. >So containers contain : what a great definition! Shrug. It is a useful descriptive term when you want to talk about things. You might keep in mind that a "container"'s _primary_ purpose is usually its containing function. So a list. But not so some arbitrary object, even though most objects have references to other objects. [...] >So I was considering a Python range object NOT being a container: indeed, range(10**6) does NOT store 10**6 integers and range(10**6) has a small memory footprint [...] >Then, mining the official docs, I realized that the collections module provides an ABC Container class allowing you to know if a given object is a container or not. And what a surprise, a range object IS a container ! You might find it duck types like other containers. [...] >The docs at : >https://docs.python.org/3.2/reference/datamodel.html#object.__contains__ >explains that a container is an object compatible with the membership test (in and not in operators). Duck typing again: this bases the term on behaviour, not memory use. >So a file is a container ? recall a file supports the in operator : Yes and no. A file can be iterated. "in" on a file reads the file as a side effect of iterating over it. A generator also supports "in", again by iteration. Neither of these things has a .__contains__ method; the "in" operator falls back to iteration if there is no .__contains__. A container usually lets you test "in" in a nondestructive/nonconsuming fashion. An iterable can be "in"ed, but it will be consumed. So iterables are not, of themselves, containers. So, range? A range object knows its bounds and state; it can answer "in" without consuming the range iteration, so it is effectively a container. Hoping this helps. Cheers, Cameron Simpson <cs@zip.com.au> [Alain] had been looking at his dashboard, and had not seen me, so I ran into him. - Jean Alesi on his qualifying prang at Imola '93
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