subclases de una pitón dict
funciona como se espera:¿Cómo se subclase un OrderedDict?
>>> class DictSub(dict):
... def __init__(self):
... self[1] = 10
...
>>> DictSub()
{1: 10}
Sin embargo, hacer lo mismo con un collections.OrderedDict
no funciona:
>>> import collections
>>> class OrdDictSub(collections.OrderedDict):
... def __init__(self):
... self[1] = 10
...
>>> OrdDictSub()
(…)
AttributeError: 'OrdDictSub' object has no attribute '_OrderedDict__root'
Por lo tanto, la aplicación OrderedDict utiliza un __root
atributo privado, lo que impide la subclase OrdDictSub
se comporta como la subclase DictSub
. ¿Por qué? ¿Cómo se puede heredar de un OrderedDict?
¿Por qué el voto a favor? – EOL