0
当我尝试检查当前局部范围或全局范围内是否有一个集合可用时,我总是得到下面的错误。为什么设置不在当地人,全局变量或变量字典
>>my_set = set()
>>my_set in locals()
>>Traceback (most recent call last):
File "<ipython-input-22-47b6756e3345>", line 1, in <module>
my_set in locals()
TypeError: unhashable type: 'set'
>>my_set in globals()
>>Traceback (most recent call last):
File "<ipython-input-22-47b6755f5503>", line 1, in <module>
my_set in globals()
TypeError: unhashable type: 'set'
>>my_set in vars()
>>Traceback (most recent call last):
File "<ipython-input-22-47b6755f9947>", line 1, in <module>
my_set in vars()
TypeError: unhashable type: 'set'
如果集不在任何这些词典(当地人,全局或增值经销商),我在哪里可以检查的,如果一组被定义?
上面没有说“不在”任何东西;它说:“类型错误:不可用类型:'设置'”,这将有望指向你在正确的方向。 – larsks
你为什么这样做?这不是在Python中检查变量的方法。将其初始化为“无”,然后检查它是否已设置为其他内容。 –
@双位炼金术士,我对python非常陌生,并且从java调整到python对我来说仍然很奇怪 –