If you want to create a dict like object using
UserDict in Python 2 and 3, there's
a couple of things to keep in mind.
UserDicthas moved to the collections module in Py3.
UserDictin Py2 is an "old-style" class. This will cause problems if using
I ran into a couple issues trying to create a dict like object that is kept in sync with a yaml file. Here's how I made it compatible with both Python versions (not the full implementation here):
from UserDict import UserDict
from collections import UserDict
class YamlDict(UserDict, object):
def update(*args, **kwargs):
super(YamlDict, self).update(*args, **kwargs)
with open('path_to_file', 'w+') as f:
object allows you to use