- 論壇徽章:
- 0
|
我的本意是把file.py讀出來,然后作為echo的參數(shù),格式化成一個字符串,然后用shell放在另外一臺機器上跑,這樣可以不用拷貝該file.py文件- In [17]: with open("file.py", "r") as f:
- data=f.read()
- print data
- ....:
- with open ("/tmp/file.py", "r") as myfile:
- data=myfile.read()
- print data
- with open ("/tmp/2", "wr") as myfile:
- myfile.write(data)
- In [18]: "echo -e %s > /tmp/1" % data
- Out[18]: 'echo -e with open ("/tmp/file.py", "r") as myfile:\n data=myfile.read()\nprint data\n\nwith open ("/tmp/2", "wr") as myfile:\n myfile.write(data)\n > /tmp/1'
復(fù)制代碼 實際上data 里包含里很多特殊字符,用%s格式化后生成的字符串在放到shell里執(zhí)行老有問題,
請問下這種情況python有沒有處理的好辦法?
謝謝! |
|