Skip to content

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

@fxjzzyo

Description

@fxjzzyo
 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)错误。。。请问,该怎么破?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions