I just upgraded to Python 2.7.1 (on Mac) so I could use OrderedDicts.
After trying to run the following script:
import collections
test = OrderedDict()
I got:
NameError: name 'OrderedDict' is not defined
I fixed it with:
from collections import OrderedDict
...but I want to know why I needed to do that?
Why didn't the broad import collections
work for me?
import collections
imports the collections module into the current namespace, so you could work with this import like this:
import collections
orderedDict = collections.OrderedDict()
from collections import OrderedDict
imports just the specified class into the current namespace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With