字符串分配语法

2024-05-15 16:52:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码片段,但有一个语法错误,我无法跟踪

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\“

请帮忙指出,不胜感激


Tags: 代码homenewservertitleconfluenceactionspace
3条回答

在您的情况下,可以使用如下字符串格式:

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

其他人已经指出,您在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)

你在标题后忘了a+

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

相关问题 更多 >