Reputation: 59
and during my studies I came across this problem:
Imagine this request body:
response = requests.get('http://somesite/somearea/api/?key=1,2,3)
It is possible to pass several values in the key.
I'm trying to create a function where I can pass multiples values as an argument
def request(*data):
d = {}
d.update({'keys':data})
return ('http://somesite/somearea/api/?key={}'.format(data))
But, the output format is incompatible:
request(1,2,3)
"http://somesite/somearea/api/?key=('1', '2', '3')"
The ideal format would be this:
"http://somesite/somearea/api/?key=1,2,3"
I don't know if I managed to be clear in my question. I'm still starting my studies, I appreciate the help
Upvotes: 1
Views: 679
Reputation: 49373
You have a tuple which you have to convert to a string:
def request(*data):
return ('http://somesite/somearea/api/?key={}'.format(','.join(map(str,data))))
print (request(1,2,3))
Upvotes: 1