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

Dan Sommers dan at
Mon Feb 27 11:52:25 CET 2012

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:


More information about the Python-list mailing list