如何在python str.replace中屏蔽doublequeotes?
我的(json)文件中有以下字符串,由于json无效,我需要替换它。
"duration": ,
我需要
"duration": NULL,
我试过
str.replace(""duration":", "duration": NULL") str.replace("""duration":"", """duration": NULL"")
但什么都没用。正确的方法是什么?
您可以将搜索字符串用单引号括起来,也可以用 \"
\"
str.replace('"duration":', '"duration": NULL')
或
str.replace("\"duration\":", "\"duration\": NULL")