May 2018
Intermediate to advanced
380 pages
9h 37m
English
UserDict is a wrapper for dictionaries that makes it easier to subclass the dict class. It has been largely replaced by the ability to subclass dict directly, but it does make it easier to work with as it allows the underlying dictionary to be accessible as an attribute. Its primary use is for backwards-compatibility, that is, versions older then Python 2.2, so if you don't need the compatibility, it is generally better to just subclass dict.
The only special thing the UserDict has beyond the normal dictionary operations is a single attribute:
data: A real dictionary to hold the contents of the UserDict class
When a UserDict is created, it accepts an optional argument of the initial data it is to hold; this initial ...