python3.6下使用translate(None, string.punctuation)去除句子中的标点符号,报错:TypeError: translate() takes exactly one argument (2 given)

原因是python版本的问题,python2下该语句正常执行,python3中translate的参数只有一个,正确做法:

sentence='The girl is a painter, and her sisiter is a dancer.'

trans=str.maketrans({key: None for key in string.punctuation})#建立转换关系

result=sentence.translate(trans)

 

相关文章:

  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2021-11-22
  • 2022-12-23
  • 2022-01-07
  • 2021-09-18
猜你喜欢
  • 2021-09-02
  • 2022-01-15
  • 2021-08-26
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
相关资源
相似解决方案