0

I have values stored in variables which i am trying to append in payload but it's not taking,please let me know how to do it

 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}}"
user3254437
  • 75
  • 1
  • 2
  • 10
  • https://stackoverflow.com/questions/517355/string-formatting-in-python – timgeb Apr 14 '18 at 08:20
  • i tried formatting but i want to get the value stored in variable s to be printed in summary in payload but it is taking only s as character – user3254437 Apr 14 '18 at 09:19
  • We can't run this code as it stands. Edit your question to provide a minimal, complete and verifiable example: https://stackoverflow.com/help/mcve . – BoarGules Apr 14 '18 at 09:32
  • i have some value say k=1234 and s=this is description,in \r\n\"description\":\"k+s\".I want to print 1234 this is description but it is printing k+s – user3254437 Apr 14 '18 at 09:51

1 Answers1

1

Issue with your code is that you have s and s+k inside the quotes and the interpreter treats it like a normal string not a variable. if you want to append 2 strings you need to use + operation.

strA = "this is string A"
strB =  "this is a string B + String A i,e " +strA
print(strB)

output

'this is a string B + String A i,e this is string A'

Here is how to append string to another string in your case:

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)

This is what i got as an output :

{
    "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"}
}}
toheedNiaz
  • 1,435
  • 1
  • 10
  • 14