[Python] TypeError: multiple bases have instance lay-out conflict

Discussão em 'Python' iniciado por Stack, Julho 5, 2025.

  1. Stack

    Stack Membro Participativo

    I wanted to create a class out of two: collections.OrderedDict and collections.DefaultDict. So that I can get an ordered dictionary and have a default value for non existing keys being accessed. Whats are some ways to do this?

    My solution was to create another class around the 2 classes I stated above. This makes an error due to a method in each class having the same name I think?

    from collections import defaultdict, OrderedDict
    class owndic(OrderedDict, defaultdict):
    pass


    producing

    TypeError: multiple bases have instance lay-out conflict


    Cheers!

    Continue reading...

Compartilhe esta Página