How to use each line at a time from an array further in requests:
The code:
x = ['param1', 'param2']
r = requests.get('http://somesite.com/?p='.format(x))
"https://www.w3schools.com/python/python_for_loops.asp" - Not working - only takes the last word from array
It works only for PRINT
CodePudding user response:
Use a python for
loop like this:
inputs = ["p1", "p2"]
result = []
for elem in inputs:
result.append(requests.get(f'http://somesite.com/?p={elem}'))
print(result)
This should do what you want.
CodePudding user response:
x = ['param1', 'param2']
for z in x
r = requests.get('http://somesite.com/?p='.format(x))
print(r)
for z in x
is a for
loop.
z could be anything, it's a placeholder for "one object in my array".
Your array has two items param1
and param2
so this will do whatever is inside that loop, in this case print
them both once.