对象没有属性...跨方法使用自我

时间:2019-06-19 20:23:10

标签: class methods self

我正在建立一个类,该类对某个单词的出现频率进行计数,但是对“ self”和“ init ”这部分代码有问题。

class FrequencySum:
    def _init_(self,min_cut = 0.1,max_cut = 0.9):
        self.min_cut = min_cut
        self.max_cut = max_cut        

    def _compute_freq(self,word_sent):
        freq = defaultdict(int)
        for s in word_sent:
            for word in s:
                if word not in stopwords: 
                    freq[word] += 1
        m = float(max(freq.values()))
        for w in freq.keys():
            freq[w] = freq[w]/m
            if freq[w] >= self.max_cut or freq[w] <= self.min_cut:
                #freq[w] = 0
                freq[w]=freq[w]
        return freq            



fs = FrequencySum
a = fs()._compute_freq(text)

我收到以下属性错误“ AttributeError:'FrequencySum'对象没有属性'max_cut'”,我不明白为什么第二种方法“ _compute_freq”不能使用self.min_cut和self.max_cut在第一个方法“ init

中使用它

0 个答案:

没有答案