首页 > 解决方案 > AttributeError:“超级”对象没有属性“word_weighting”

问题描述

我有一个超级班FTM

class FTM:
    def __init__(self,word_weighting = 'normal'):
        self.word_weighting = word_weighting
    
    def get_sparse_global_term_weights(self, word_weighting):
        pass

还有一个继承自的子类FTM

class FLSA(FTM):
    def __init__(self, word_weighting='normal'):
        super().__init__(word_weighting = word_weighting)
        self.sparse_global_term_weighting = super().get_sparse_global_term_weights(word_weighting = super().word_weighting)
        

运行此代码,我收到以下错误:

AttributeError: 'super' object has no attribute 'word_weighting'

我已经初始化了属性。为什么我会收到此错误?

标签: python-3.xclassinheritanceattributeerrorsuper

解决方案


推荐阅读