为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

侃侃尔雅 2019-10-18 14:40:07
我在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!
查看完整描述

1 回答

?
哔哔one

TA贡献1854条经验 获得超8个赞

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!"


查看完整回答
反对 回复 2019-10-18
  • 1 回答
  • 0 关注
  • 253 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信