Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20932

Re: How can I make an instance of a class act like a dictionary?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:activestate': 0.09; 'class,': 0.15; '__init__': 0.16; 'class:': 0.16; 'dictionary,': 0.16; 'subject:instance': 0.16; 'variable.': 0.16; 'this:': 0.16; 'wrote:': 0.18; 'instance': 0.18; 'feb': 0.22; 'fine,': 0.23; 'url:code': 0.28; 'class': 0.29; '(and': 0.30; 'sun,': 0.30; 'received:24': 0.31; 'subject:?': 0.31; 'header:User-Agent:1': 0.33; 'header:X-Complaints-To:1': 0.34; 'rather': 0.34; 'to:addr :python-list': 0.35; 'subject:How': 0.35; 'subject:can': 0.35; 'received:org': 0.36; 'everyone.': 0.37; 'created': 0.37; 'but': 0.37; 'could': 0.38; 'to:addr:python.org': 0.40; 'john': 0.61; 'custom': 0.61; 'subject:like': 0.67; 'subject:make': 0.73
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dan Sommers <dan@tombstonezero.net>
Subject Re: How can I make an instance of a class act like a dictionary?
Date Mon, 27 Feb 2012 10:52:25 +0000 (UTC)
References <a48bde30-31ed-45a9-ba89-6559c17d0992@y17g2000yqg.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host 24.100.92.194
User-Agent Pan/0.133 (House of Butterflies)
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.191.1330339962.3037.python-list@python.org> (permalink)
Lines 17
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1330339962 news.xs4all.nl 6947 [2001:888:2000:d::a6]:42289
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20932

Show key headers only | View raw


On Sun, 26 Feb 2012 23:24:31 -0800, John Salerno wrote:

> Hi everyone. I created a custom class and had it inherit from the "dict"
> class, and then I have an __init__ method like this:

> I know I could do self.variable = create() and that works fine, but I
> thought it would be better (and cleaner) simply to use the instance
> itself as the dictionary, rather than have to go through an instance
> variable.

Check out the "Bunch" class:

    http://code.activestate.com/recipes/52308/

HTH,
Dan

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

How can I make an instance of a class act like a dictionary? John Salerno <johnjsal@gmail.com> - 2012-02-26 23:24 -0800
  Re: How can I make an instance of a class act like a dictionary? Chris Rebert <clp2@rebertia.com> - 2012-02-26 23:39 -0800
    Re: How can I make an instance of a class act like a dictionary? John Salerno <johnjsal@gmail.com> - 2012-02-27 12:09 -0800
      Re: How can I make an instance of a class act like a dictionary? Benjamin Kaplan <benjamin.kaplan@case.edu> - 2012-02-27 15:37 -0500
  Re: How can I make an instance of a class act like a dictionary? Dan Sommers <dan@tombstonezero.net> - 2012-02-27 10:52 +0000

csiph-web