Python字符串删除';特朗普总统\\xe2\\x80\\x99s';

Python字符串删除';特朗普总统\\xe2\\x80\\x99s';,python,string,hex,Python,String,Hex,我找了一会儿,但找不到有用的东西。 我试图在Paython列表中删除字符串中的这些十六进制代码,但不知道如何删除。它们是字符串格式的! 除了我的数据(特朗普推特获取): 谢谢大家! 试试这种方法,它只适用于子字符串“\\x**”: import re tweets = 'rt @ lindseygrahamsc : i support president trump\\xe2\\x80\\x99s desire to reenter the paris accord after the agre

我找了一会儿,但找不到有用的东西。 我试图在Paython列表中删除字符串中的这些十六进制代码,但不知道如何删除。它们是字符串格式的! 除了我的数据(特朗普推特获取):


谢谢大家!

试试这种方法,它只适用于子字符串“
\\x**
”:

import re
tweets = 'rt @ lindseygrahamsc : i support president trump\\xe2\\x80\\x99s desire to reenter the paris accord after the agreement becomes a better deal for america\\xe2\\x80\\xa6'
re.sub(r'(\\x(.){2})', '',tweets)
输出:

'rt @ lindseygrahamsc : i support president trumps desire to reenter the paris accord after the agreement becomes a better deal for america'

您是要删除十六进制代码还是询问它们是否可以转换为ASCII码?(请注意,这些都是大于128的数字,因此不是标准ASCII集的一部分。)很难为您提供帮助,因为您没有提供获取此字符串的详细信息。顺便说一句,也许你应该回到问题的根源,在你收到推文时正确地编码,例如status.text.encode(“utf-8”),谢谢!我只想删除它们,并把重点放在纯文本上,所以在这个方向上的一些解决方案将是伟大的!我得到了一个快速而肮脏的小解决方法:
'.join([w在new中代表w.replace('\\','*')).split()如果不是w.startswith('*')))
'rt @ lindseygrahamsc : i support president trumps desire to reenter the paris accord after the agreement becomes a better deal for america'