如何在这里添加字符串

时间:2018-04-14 08:15:18

标签: python

我有值存储在变量中,我试图在有效负载中附加但是它没有接受,请告诉我该怎么做

 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}}"

1 个答案:

答案 0 :(得分:1)

您的代码问题在于引号内有ss+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"}
}}