2016-04-12 40 views
0
for element in self.table1.find({'ji': {'$ne': ""}}): 
    gongLiNian = int(element['gongLiNian']) 
    gongLiNianScope = [str(gongLiNian-1), str(gongLiNian), str(gongLiNian+1)] 
    res = self.table2.find_one({'guanZhi' : element['guanZhi'], 
          'gongLiNian' : {'$in', gongLiNianScope}, 
           'name' : element['name']}) 

對於這段代碼,這裏是錯誤:

Traceback (most recent call last): 
    File "C:\Users\elqstux\Desktop\study\History\oneJi.py", line 172, in <module> 
    oneJi.run() 
    File "C:\Users\elqstux\Desktop\study\History\oneJi.py", line 158, in run 
    res1 = self.step1() 
    File "C:\Users\elqstux\Desktop\study\History\oneJi.py", line 44, in step1 
    'gongLiNian' : {'$in', gongLiNianScope}, 
TypeError: unhashable type: 'list' 

但我無法找到從error.Could你能給我一些建議任何線索?

回答

1

在這裏看到了逗號:

{'$in', gongLiNianScope} 

這是一個語法來初始化設置,你可以把只哈希的數據類型爲一組。

相反,你的意思是有一個字典:

{'$in': gongLiNianScope} 
相關問題