我写这样的代码:如何在python通过string.pronunciation和string.whitespace同时分割字符串
import re
import string
new_string = re.split(string.pronunciation|string.whitespace, string)
,但它不工作
我写这样的代码:如何在python通过string.pronunciation和string.whitespace同时分割字符串
import re
import string
new_string = re.split(string.pronunciation|string.whitespace, string)
,但它不工作
尝试new_string = re.split('[%s]' % (string.punctuation + string.whitespace), 'Some. String')
由于您可以在错误消息中看到,str
s不支持运营商|
,您可能错误输入了punctuation
作为pronunciation
。
然后它显示: –
文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/sre_parse.py”,行641,在_parse source.tell() - here + len(this )) sre_constants.error:在位置10(第1行,第11列)处重复多次 –
是的,我编辑过它。现在检查它 – hallazzang
欢迎来到Stack Overflow!您可以先[参观](http://stackoverflow.com/tour)并学习[如何提出一个好问题](http://stackoverflow.com/help/how-to-ask)并创建一个[最小,完整和可验证](http://stackoverflow.com/help/mcve)示例。这使我们更容易帮助你。 –
你想用你的代码实现什么? – abccd