解决python3.x报错 AttributeError: module ‘string’ has no attribute ‘maketrans’
出错代码为:
text_string = content[1].translate(string.maketrans("", ""), string.punctuation)
报错 :AttributeError: module ‘string’ has no attribute ‘maketrans’
1. 将string.maketrans修改为 str.maketrans
重新运行后,会报另一个错误:
TypeError: translate() takes exactly one argument (2 given)
2.将 string.punctuation删除
重新运行即可。
最终修改为:
#text_string = content[1].translate(string.maketrans("", ""), string.punctuation)
text_string = content[1].translate(str.maketrans("", ""))