Skip to main content
 首页 » 编程设计

python之string.translate() 不接受 2 个参数

2024年10月01日7myhome

<分区>

我看了几个答案 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 兼容。否则我很难过。任何帮助,将不胜感激。