簡體   English   中英

如何修復 TypeError: unhashable type: 'dict'

[英]How to fix TypeError: unhashable type: 'dict'

**解壓Function:從壓縮function加載文件bin

def lzwDecompressionText () :
loadCompressed = open ("CompreText.bin","rb")
compressed = pickle.load(loadCompressed)    
print("", compressed)
dictionary =defaultdict(dict)
lenDictionary = 256
decompressed_data = ""
string=""
for i in range(256):
    dictionary[i] = chr(i)
Traceback (most recent call last):
  File "c:/Users/anton/Documents/GitHub/Project-LZW/LZW-Project/test.py", line 21, in <module>
    lzwDecompressionText()
  File "c:\Users\anton\Documents\GitHub\Project-LZW\LZW-Project\textLzw.py", line 70, in lzwDecompressionText
    if not (code in dictionary):
TypeError: unhashable type: 'dict'
for code in compressed:
    if not (code in dictionary):
        dictionary[code] = string + (string[0])
decompressed_data += dictionary[code]
if not(len(string) == 0):
    dictionary[lenDictionary] = string + (dictionary[code][0])
    lenDictionary += 1
string = dictionary[code]

似乎至少有一些compressed (從腌制文件加載)中的code值恰好是dict類型,這與您對int的期望相反。

另請參閱: TypeError: Unhashable type

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM