我有这样一句话:
"My name is Manuel, the "most handsome""我转义它是因为我想把它放在一个json中,它看起来像这样:
sentence=sentence.replace(""","\"")
"My name is Manuel, the \"most handsome\""现在我必须采用引号中的位置,也就是:最漂亮的位置,但是给我一个finditer的位置,它计算反斜杠\我不想让它计算它,有没有一种方法我不能计算反斜杠
发布于 2020-07-09 20:38:57
仅将"替换为":sentence = sentence.replace(""",'"')。要获得JSON表示,请使用json模块中的json.dumps()。
>>> import json
>>> sentence = "My name is Manuel, the "most handsome""
>>> sentence = sentence.replace(""",'"')
>>> print(sentence)
My name is Manuel, the "most handsome"
>>> sentence.find('"')
23
>>> sentence[23:]
'"most handsome"'
>>> print(json.dumps(sentence))
"My name is Manuel, the \"most handsome\""https://stackoverflow.com/questions/62814931
复制相似问题