1,解决TypeError: a bytes-like object is required, not 'str'
py2:
words = line.split()
py3 改爲:
words = line.decode().split()
2, 解决 translate() takes exactly one argument (2 given)问题
py3 只带有一个参数
py2
word = word.translate(NONE,string.punctuation)
需要使用str.maketrans改为:
remove = string.punctuation table = str.maketrans('', '', remove) word = word.translate(NONE,string.punctuation)