我有值存储在变量中,我试图在有效负载中附加但是它没有接受,请告诉我该怎么做
r=(issues["fields"]["resolution"]["name"])
#print (r)
p=(issues["fields"]["customfield_13709"])
#print (p)
s=(issues["fields"]["summary"])
#print(s)
k=(issues["key"])
#print(k)
a=(issues["fields"]["assignee"]["name"])
#print (a)
payload = "{\r\n\t\"fields\":{\r\n\"project\":{\"key\":\"SSETOPS\"},\r\n\"summary\":\"s\",\r\n\"description\":\"k+s\",\r\n\"issuetype\":{\"name\":\"Task\"},\r\n\"customfield_12610\":{\"value\":\"High\"},\r\n\"components\":[{\"name\":\"Other\"}],\r\n\"assignee\":{\"name\":\"rahsingh\"}\r\n}}"
答案 0 :(得分:1)
您的代码问题在于引号内有s
和s+k
,解释器将其视为普通字符串而不是变量。如果你想附加2个字符串,你需要使用+操作。
strA = "this is string A"
strB = "this is a string B + String A i,e " +strA
print(strB)
<强>输出强>
'this is a string B + String A i,e this is string A'
以下是如何在您的案例中将字符串附加到另一个字符串:
s = "some summary" #Assumed some Values
k = "something else"
payload = "{\r\n\t\"fields\":{\r\n\"project\":{\"key\":\"SSETOPS\"},\r\n\"summary\":" +'\"'+ s +'\"'+ ",\r\n\"description\":" +'\"'+ k+" "+s +'\"'+ ",\r\n\"issuetype\":{\"name\":\"Task\"},\r\n\"customfield_12610\":{\"value\":\"High\"},\r\n\"components\":[{\"name\":\"Other\"}],\r\n\"assignee\":{\"name\":\"rahsingh\"}\r\n}}"
print(payload)
这是我作为输出获得的:
{
"fields":{
"project":{"key":"SSETOPS"},
"summary":"some summary",
"description":"something else some summary",
"issuetype":{"name":"Task"},
"customfield_12610":{"value":"High"},
"components":[{"name":"Other"}],
"assignee":{"name":"rahsingh"}
}}