在python2.7中删除字符串中的unicode \ u2026喜欢的字符

我在python2.7中有一个这样的字符串,


 This is some \u03c0 text that has to be cleaned\u2026! it\u0027s annoying!

我如何将其转换为此,


This is some text that has to be cleaned! its annoying!


侃侃尔雅
浏览 254回答 1
1回答

哔哔one

Python 2.x>>> s'This is some \\u03c0 text that has to be cleaned\\u2026! it\\u0027s annoying!'>>> print(s.decode('unicode_escape').encode('ascii','ignore'))This is some  text that has to be cleaned! it's annoying!Python 3.x>>> s = 'This is some \u03c0 text that has to be cleaned\u2026! it\u0027s annoying!'>>> s.encode('ascii', 'ignore')b"This is some  text that has to be cleaned! it's annoying!"
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python