python errors

Q1

1
2
3
4
5
6
7
2019-07-31 17:23:44,663 - jms_perm.py - INFO - perm_key: (['名字(zhi.ming)'], ['v-hostname.hx(10.10.100.100)'])
Traceback (most recent call last):
File "jms_perm.py", line 338, in <module>
perm_args_list = perm_process()
File "jms_perm.py", line 318, in perm_process
long_time_perms[perm_key] = perm
TypeError: unhashable type: 'list'

A1

Python dict的key必须为hashable

问题中key中包含list或dict类型,所以报错.

可哈希的元素有:int, float, str, tuple
不可哈希的元素有:list, set, dict

简单说在元素生命周期中,元素值会发布变动的为unhashable