Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从字符串python中删除\xe2\x80\xa6_Python_String_Replace_Ascii - Fatal编程技术网

从字符串python中删除\xe2\x80\xa6

从字符串python中删除\xe2\x80\xa6,python,string,replace,ascii,Python,String,Replace,Ascii,我有很多txt文件,我需要替换其中的一些文本。几乎所有的字符都是非ascii字符(我原以为是“…”,但…不一样) 我用replace()试过了,但是不行,我需要一些帮助!!提前感谢如果您使用打开文件,那么您将获得所有字符串作为unicodes,它们是。使用unicode类型的字符串。比如说, >>> print u'\xe2'.replace(u'\xe2','a') a 问题是这些字符是无效的string,它们是unicode import re re.sub(r'<

我有很多txt文件,我需要替换其中的一些文本。几乎所有的字符都是非ascii字符(我原以为是“…”,但…不一样)
我用
replace()
试过了,但是不行,我需要一些帮助!!提前感谢

如果您使用打开文件,那么您将获得所有字符串作为
unicode
s,它们是。

使用unicode类型的字符串。比如说,

>>> print u'\xe2'.replace(u'\xe2','a')
a

问题是这些字符是无效的
str
ing,它们是
unicode

import re
re.sub(r'<string to repleace>','',text,re.U)
重新导入
re.sub(r'','',文本,re.U)
大多数其他答案也适用