Fix "NameError: name 'OrderedDict' is not defined"

To fix the NameError OrderedDict is not defined error, do the following:

import collections
    from collections import OrderedDict
except ImportError:
    OrderedDict = dict

The OrderedDict is available in more recent versions of python. Use this as a fallback for OrderedDict support.

$ python
Traceback (most recent call last):
  File "", line 8, in <module>
    foo = OrderedDict()
NameError: name 'OrderedDict' is not defined
This post is available on GitHub.
Posted .


Leave a Reply