python AttributeError:类XXX没有属性' __ class __'

时间:2017-08-15 10:25:15

标签: python python-2.7 attributeerror

谁能帮我解决这个例外?

 File "/root/anaconda2/lib/python2.7/site-packages/numba/dispatcher.py", line 305, in _compile_for_args
argtypes.append(self.typeof_pyval(a))
File "/root/anaconda2/lib/python2.7/site-packages/numba/dispatcher.py", line 429, in typeof_pyval
  File "/root/anaconda2/lib/python2.7/site-packages/numba/typing/typeof.py", line 28, in typeof
ty = typeof_impl(val, c)
File "/root/anaconda2/lib/python2.7/site-packages/singledispatch.py", line 210, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
AttributeError: class FeatureEncoding has no attribute '__class__'

1 个答案:

答案 0 :(得分:0)

并非每个实例都具有__class__属性。只是一般性建议:在大多数情况下,最好使用type代替__class__

例如,旧式课程没有课程:

>>> class A:
...   pass
...
>>> A.__class__
AttributeError: class A has no attribute '__class__'

>>> int.__class__  # just for comparison the class of the int class
<type 'type'>

type有效:

>>> type(A)
<type 'classobj'>

注意:旧式类的实例具有__class__属性

>>> a = A()
>>> a.__class__
<class __main__.A at 0x0000000002E61168>