sentiment-analysis icon indicating copy to clipboard operation
sentiment-analysis copied to clipboard

你好,我运行你的代码出现了一个错误

Open fxjzzyo opened this issue 7 years ago • 0 comments

 for line in file:
        line = line.lower().encode('utf-8')
        words = line.split()
        for word in words:
            word = word.translate(None, string.punctuation)
            if word != '':
                allWords.append(word)

这段代码,的word.translate(None, string.punctuation)一句,报TypeError: a bytes-like object is required, not 'str'这个错误。在网上查了下,说可能是py3.5的问题,加上decode后,又报了TypeError: translate() takes exactly one argument (2 given)错误。。。请问,该怎么破?

fxjzzyo avatar Jul 10 '18 02:07 fxjzzyo