2014-07-21 67 views
0

我有下面的代碼片段,但有一個語法錯誤,我無法跟蹤。字符串分配語法錯誤

space = "space" 
title = "new" 
content = "content" 
command ='confluence --action storePage --space \"' + space + '\" --title \"' + title '\" --parent \"@home\" --content \"' + content + '\" --noConvert --server <server> --user <user> --password <password>' 

由Python解釋指出語法錯誤是在--content \」'

在指出它是知道的任何幫助。

+1

如果你正在運行一個命令,採取子庫一看,這將確保它逃跑的所有參數。 – denisvm

+0

好的,我使用的是os.system(),但我會看看它,謝謝! – aishpr

回答

3

後,您忘了+標題

command ='confluence --action storePage --space \"' + space + '\" --title \"' + title + '\" --parent \"@home\" --content \"' + content + '\" --noConvert --server <server> --user <user> --password <password>' 
+0

是的!謝謝!我不知道爲什麼我沒有注意到它! – aishpr

2

你的情況,你可以使用字符串格式化是這樣的:

space = "space" 
title = "new" 
content = "content" 
command_string = "programm --space %(space) --title %(title) --content %(content)" 
command = command_string % {'space': space, 'title': title, 'content': content} 
2

其他人已經指出你在title之後忘了+。 使用不易出錯的符號可能有助於避免這種錯誤的:

space = "space" 
title = "new" 
content = "content" 
command ='confluence --action storePage --space \"{}\" --title \"{}\" --parent \"@home\" --content \"{}\" --noConvert --server <server> --user <user> --password <password>'.format(space, title, content)