Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #15041
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.011 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'oct': 0.02; 'memory.': 0.05; 'behavior,': 0.07; 'infinite': 0.07; 'types:': 0.09; 'def': 0.15; 'argument': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'received:209.85.210.174': 0.18; 'received:mail- iy0-f174.google.com': 0.18; 'memory': 0.21; 'header:In-Reply- To:1': 0.22; 'pm,': 0.24; 'thu,': 0.28; '27,': 0.29; 'message- id:@mail.gmail.com': 0.29; 'booth': 0.30; 'class': 0.30; "didn't": 0.31; 'to:addr:python-list': 0.33; 'however,': 0.34; 'object': 0.35; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'either': 0.39; "couldn't": 0.39; 'to:addr:python.org': 0.39; "it's": 0.40; 'more': 0.60; 'easily': 0.61; '10:03': 0.84; 'compelling': 0.84; 'recursion,': 0.84; 'subject:types': 0.84; '-->': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=YN7vpCTYpQyIhm+3BeNjolAzRAbytzQdhhgaaDlS3sg=; b=nSTqtCxWEYXBEoySsudKEGzaAiKjJGQV148gKqWh0UbzwHz/dqXs6pxRhEOpX6gADB UfCqbAG+iuCOBjtUURXpnNOJPcJ5eg1khaPOljXnFuenUA/9E9C9/TKlSMGWxYDNzl8g ijC892THn9rGc6RQIq5/Un/7kI2ccmQfwSNpg= |
| MIME-Version | 1.0 |
| In-Reply-To | <Xns9F8B7A9C6BEE5duncanbooth@127.0.0.1> |
| References | <4ea92dae$0$20639$426a74cc@news.free.fr> <Xns9F8B7A9C6BEE5duncanbooth@127.0.0.1> |
| Date | Fri, 28 Oct 2011 00:25:19 +1100 |
| Subject | Re: __dict__ attribute for built-in types |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2255.1319721922.27778.python-list@python.org> (permalink) |
| Lines | 31 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1319721922 news.xs4all.nl 6929 [2001:888:2000:d::a6]:38445 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:15041 |
Show key headers only | View raw
On Thu, Oct 27, 2011 at 10:03 PM, Duncan Booth
<duncan.booth@invalid.invalid> wrote:
> Types without a __dict__ use less memory. Also, if you couldn't have a
> type that didn't have a `__dict__` then any `dict` would also need its
> own `__dict__` which would either result in infinite memory use or
> recursive dictionaries.
>
Easy, just self-reference.
a = {}
a.__dict__ is a --> True
Yeah, it's recursion, but no different from types:
>>> type(type) is type
True
If you want this behavior, you can do it easily enough.
>>> class dictdict(dict):
def __init__(self):
self.__dict__=self
>>> a=dictdict()
>>> a.__dict__ is a
True
However, the more compelling argument is that a __slots__ object can
be WAY more efficient.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
__dict__ attribute for built-in types candide <candide@free.invalid> - 2011-10-27 12:08 +0200
Re: __dict__ attribute for built-in types Arnaud Delobelle <arnodel@gmail.com> - 2011-10-27 11:36 +0100
Re: __dict__ attribute for built-in types Duncan Booth <duncan.booth@invalid.invalid> - 2011-10-27 11:03 +0000
Re: __dict__ attribute for built-in types Chris Angelico <rosuav@gmail.com> - 2011-10-28 00:25 +1100
Re: __dict__ attribute for built-in types Duncan Booth <duncan.booth@invalid.invalid> - 2011-10-27 14:36 +0000
Re: __dict__ attribute for built-in types Chris Angelico <rosuav@gmail.com> - 2011-10-28 09:39 +1100
Re: __dict__ attribute for built-in types candide <candide@free.invalid> - 2011-10-27 16:01 +0200
Re: __dict__ attribute for built-in types Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-10-27 22:19 +0000
Re: __dict__ attribute for built-in types candide <candide@free.invalid> - 2011-10-28 00:52 +0200
Re: __dict__ attribute for built-in types Terry Reedy <tjreedy@udel.edu> - 2011-10-27 22:44 -0400
Re: __dict__ attribute for built-in types alex23 <wuwei23@gmail.com> - 2011-10-27 19:48 -0700
Re: __dict__ attribute for built-in types Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-10-28 08:01 +0000
Re: __dict__ attribute for built-in types candide <candide@free.invalid> - 2011-10-28 12:03 +0200
Re: __dict__ attribute for built-in types Christian Heimes <lists@cheimes.de> - 2011-10-28 13:51 +0200
Re: __dict__ attribute for built-in types Peter Pearson <ppearson@nowhere.invalid> - 2011-10-28 15:52 +0000
Re: __dict__ attribute for built-in types Hrvoje Niksic <hniksic@xemacs.org> - 2011-10-28 00:57 +0200
Re: __dict__ attribute for built-in types candide <candide@free.invalid> - 2011-10-28 01:36 +0200
Re: __dict__ attribute for built-in types MRAB <python@mrabarnett.plus.com> - 2011-10-28 01:02 +0100
Re: __dict__ attribute for built-in types candide <candide@free.invalid> - 2011-10-28 04:46 +0200
Re: __dict__ attribute for built-in types Patrick Maupin <pmaupin@gmail.com> - 2011-10-27 20:02 -0700
Re: __dict__ attribute for built-in types candide <candide@free.invalid> - 2011-10-28 12:04 +0200
Re: __dict__ attribute for built-in types Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-10-28 06:21 +0000
Re: __dict__ attribute for built-in types Hrvoje Niksic <hniksic@xemacs.org> - 2011-10-28 11:08 +0200
Re: __dict__ attribute for built-in types candide <candide@free.invalid> - 2011-10-28 12:23 +0200
Re: __dict__ attribute for built-in types Nobody <nobody@nowhere.com> - 2011-10-28 06:49 +0100
csiph-web