在python2.7中删除字符串中的unicode u2026之类的字符 [英] Removing unicode u2026 like characters in a string in python2.7
本文介绍了在python2.7中删除字符串中的unicode u2026之类的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在python2.7中有一个这样的字符串,
这是一些u03c0 必须清理的文本u2026!真烦人!
我如何将其转换为这个,
这是一些必须清理的文本!这很烦人!
解决方案
Python 2.x
<预><代码>>>>秒'这是一些必须清理的 \u03c0 文本\u2026!它很烦人!>>>打印(s.decode('unicode_escape').encode('ascii','ignore'))这是一些必须清理的文本!这很烦人!Python 3.x
<预><代码>>>>s = '这是一些u03c0 必须清理的文本u2026!真烦人!>>>s.encode('ascii', '忽略')b这是一些必须清理的文字!很烦人!"I have a string in python2.7 like this,
This is some u03c0 text that has to be cleanedu2026! itu0027s annoying!
How do i convert it to this,
This is some text that has to be cleaned! its annoying!
解决方案
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 cleanedu2026! itu0027s annoying!'
>>> s.encode('ascii', 'ignore')
b"This is some text that has to be cleaned! it's annoying!"
这篇关于在python2.7中删除字符串中的unicode u2026之类的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文