标签:and type nbsp sla 执行 erro Painter tran result
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)
TypeError: translate() takes exactly one argument (2 given)
标签:and type nbsp sla 执行 erro Painter tran result
原文地址:https://www.cnblogs.com/yangruicvpr/p/9938698.html