Inheriting from OrderedDict causes problem

Bruce Eckel lists.eckel at gmail.com
Wed Feb 22 12:33:12 EST 2012


On Feb 22, 10:10 am, Peter Otten <__pete... at web.de> wrote:
> Looks like invoking OrderedDict.__init__() is necessary:
>
> >>> from collections import OrderedDict
> >>> class X(OrderedDict):
>
> ...     def __init__(self, stuff):
> ...             super(X, self).__init__()
> ...             for k, v in stuff:
> ...                     self[k] = v
> ...>>> X([("a", "b"), ("c", "d")])
>
> X([('a', 'b'), ('c', 'd')])

Thank you! That worked. Languages. Some of them automatically call the
default base-class constructors, others don't. Apparently.



More information about the Python-list mailing list