【发布时间】:2023-03-16 04:00:02
【问题描述】:
我看过几个答案 Best way to strip punctuation from a string in Python 但这些似乎都没有解决我的问题。我正在尝试使用 string.translate() 从字符串中去除标点符号。
当我运行代码时:
import string
s = "This. has? punctuation,"
noPunct = s.translate(s.maketrans("",""), string.punctuation)
我明白了:
TypeError: translate() takes exactly one argument (2 given)
这可能是我使用的 python 版本的问题吗?我正在使用 python 3.5.4 与 nltk 兼容。否则我很难过。任何帮助,将不胜感激。
【问题讨论】:
标签: python python-3.x