Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.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替换文件中的特殊字符?_Python_Python 3.x_Python 2.7 - Fatal编程技术网

如何使用Python替换文件中的特殊字符?

如何使用Python替换文件中的特殊字符?,python,python-3.x,python-2.7,Python,Python 3.x,Python 2.7,我的档案里有这样的数据。我想替换整个数据中的反斜杠。我在阅读此文本文件后尝试使用replace函数,但没有得到结果。你能帮忙吗 [{"Name": "Segment1", "Value": 14.0, "Categories": "{\"MILL CREEK\": 0.0, \"FAIRPORT\": 1.0, \"PENNINGTON\": 0.0, \"GREENWICH\": 0.0 您需要转义反斜杠字符 str.replace('\\', "") 嗨,Shankar,发布你尝试过的代

我的档案里有这样的数据。我想替换整个数据中的反斜杠。我在阅读此文本文件后尝试使用replace函数,但没有得到结果。你能帮忙吗

[{"Name": "Segment1", "Value": 14.0, "Categories": "{\"MILL CREEK\": 0.0, \"FAIRPORT\": 1.0, \"PENNINGTON\": 0.0, \"GREENWICH\": 0.0

您需要转义反斜杠字符

str.replace('\\', "")

嗨,Shankar,发布你尝试过的代码总是很有帮助的。可能是重复的