Skip to content
Advertisement

Adding an attribute to a Python dictionary from the standard library

I was wondering if you could add an attribute to a Python dictionary?

JavaScript

Is there anyway to quickly add my description attribute without having to copy the dict class and overloading the constructor. I thought it would be simple, but I guess I was wrong.

Advertisement

Answer

Just derive from dict:

JavaScript

Instances of MyDict behave like a dict, but can have custom attributes:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement