Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-将`set.union`指定为类属性_Python_Set_Python Descriptors - Fatal编程技术网

Python-将`set.union`指定为类属性

Python-将`set.union`指定为类属性,python,set,python-descriptors,Python,Set,Python Descriptors,将set.union指定为类的属性,并从该类的实例变量调用此属性时,将引发错误:TypeError:set对象的描述符“union”不适用于“Foo”对象。下面是一个例子来说明这个问题: Foo类: bar=set.union set.union({1},{2}) # {1, 2} Foo.bar({1},{2}) # {1, 2} Foo().bar({1},{2}) #回溯(最近一次呼叫最后一次): #文件“”,第1行,在 #TypeError:“set”对象的描述符“union”不适用于“

set.union
指定为类的属性,并从该类的实例变量调用此属性时,将引发错误:
TypeError:set对象的描述符“union”不适用于“Foo”对象
。下面是一个例子来说明这个问题:

Foo类:
bar=set.union
set.union({1},{2})
# {1, 2}
Foo.bar({1},{2})
# {1, 2}
Foo().bar({1},{2})
#回溯(最近一次呼叫最后一次):
#文件“”,第1行,在
#TypeError:“set”对象的描述符“union”不适用于“Foo”对象
set.union
指定为实例属性时不会发生这种情况:

class Foobar:
定义初始化(自):
self.bar=set.union
Foobar().bar({1},{2})
# {1, 2}
是什么导致了这个错误?为什么这只发生在类属性中