OrderedDict()的不可变实例

时间:2015-06-24 14:55:52

标签: python ordereddictionary

在python中使用以下代码时,你能帮我解决这个TypeError吗?

from collections import OrderedDict
from PIL import Image

img = 'image_0024.jpg'
imgin = Image.open(img)
imgin = imgin.convert('RGB')

resultado = OrderedDict()
resultado[imgin] = 0

这会产生一个TypeError,你能解释一下这个OrderedDict的问题是什么吗?

TypeError                                 Traceback (most recent call last)
<ipython-input-5-5a96d484923f> in <module>()
      7 
      8 resultado = OrderedDict()
----> 9 resultado[imgin] = 0
     10 
     11 print resultado

/home/drueda/anaconda/lib/python2.7/collections.pyc in __setitem__(self, key, value, dict_setitem)
     61         # Setting a new item creates a new link at the end of     the linked list,
     62         # and the inherited dictionary is updated with the new key/value pair.
---> 63         if key not in self:
     64             root = self.__root
     65             last = root[0]

TypeError: unhashable instance

0 个答案:

没有答案