我写了这个简单的小程序:如何替换斜杠反斜杠 - Python的
def main ():
with open("test.txt", "rt") as fin:
with open("out.txt", "wt") as fout:
for line in fin:
fout.write(line.replace("\", "/"))
print ("done")
的main()
我知道,“\”是在Python字面逃跑,但我需要的是扫描文本文件并用正斜杠“/”替换每一个间隙。
任何人都知道该怎么办?
也许用“\\”呢? –
[在Python中用正斜杠替换反斜杠]的可能重复(http://stackoverflow.com/questions/4119166/replace-backslashes-with-forward-slashes-in-python) – McGrady