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?

From Dan Sommers <dan@tombstonezero.net>
Subject Re: How can I make an instance of a class act like a dictionary?
Date 2012-02-27 10:52 +0000
References <a48bde30-31ed-45a9-ba89-6559c17d0992@y17g2000yqg.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.191.1330339962.3037.python-list@python.org> (permalink)

Show all headers | 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