-4
我正試圖用python的open打開下面的代碼。但是,我無法將轉義序列「\」放在正確的位置,從而導致錯誤。蟒蛇的逃脫序列
代碼:
#!/usr/bin/python
f = open("hello.service", "w")
f.write("[Unit]")
f.write("Description=Hello World")
f.write("[Service]")
f.write("ExecStart=/bin/bash -c \"while true; do echo \"Hello, world"\; sleep 1; done""\)
f.close()
錯誤:
$ python hello.py
File "hello.py", line 7
f.write("ExecStart=/bin/bash -c \"while true; do echo \"Hello, world"\; sleep 1; done""\)
^
SyntaxError: unexpected character after line continuation character
任何幫助將是非常可觀的。
我覺得應該是'世界\「'爲了逃避''''和'完成'後'''' – Arman
檢查你的問題中的顏色:他們幫助:) –
pro-tip:使用三引號,所以你不必轉義任何東西:''「」一個字符串「用一些雙引號」和「一些單引號」「」「' –