-1

my code is as below

aaa = "['https://google.com', 'https://yahoo.com']"
REQUEST = f'{"siteUrls": {aaa}}'
print(REQUEST)

I've tried

aaa = "['https://google.com', 'https://yahoo.com']"
REQUEST = {"siteUrls": {}}.format(aaa)
print(REQUEST)

and

aaa = "['https://google.com', 'https://yahoo.com']"
REQUEST = {"siteUrls": %s}%aaa
print(REQUEST)

all of them didn't work
REQUEST must be dict.
please help.

Jeremy
  • 19
  • 4
  • 1
    Why is `aaa` a string and not a list, and why are you using string formation instead of the `json` module to build the request payload? – chepner Jul 11 '22 at 16:56
  • What you *probably* want is `aaa = ['https://google.com', 'https://yahoo.com']` (you may need to figure out how to parse a given string back to a Python list first), then `REQUEST = {'siteUrls': aaa}`. – chepner Jul 11 '22 at 16:59
  • because I'm beginner. if aaa is a list is it better to resolve this issue? @chepner – Jeremy Jul 11 '22 at 17:15
  • Yes; build the data structure first, *then* encode as JSON (if necessary) as the very last step before sending the request. – chepner Jul 11 '22 at 17:19
  • aaa is a var, collects urls of products. so I think aaa should be a list. @chepner – Jeremy Jul 11 '22 at 17:21
  • could you provide codes please @chepner – Jeremy Jul 11 '22 at 17:24
  • What produces `aaa` in the first place? It should just not create the string from whatever list it starts with. – chepner Jul 11 '22 at 17:25
  • `aaa = ['https://google.com', 'https://yahoo.com'] REQUEST = { "siteUrls": [f'{aaa[0]}']}` this works, thank you for your comments – Jeremy Jul 12 '22 at 01:12

1 Answers1

0

try this

aaa = "['https://google.com', 'https://yahoo.com']"
REQUEST = {"siteUrls": f"{aaa}"}
print(REQUEST)
r3a9670
  • 178
  • 6
  • `aaa = ['https://google.com', 'https://yahoo.com']` `REQUEST = { "siteUrls": [f'{aaa[0]}']}` it works! thank yhou @r3a9670 – Jeremy Jul 12 '22 at 01:08