2014-07-21 63 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)