How can I make an instance of a class act like a dictionary?
Dan Sommers
dan at tombstonezero.net
Mon Feb 27 05:52:25 EST 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:
http://code.activestate.com/recipes/52308/
HTH,
Dan
More information about the Python-list
mailing list