我寫了這個簡單的小程序:如何替換斜槓反斜槓 - 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