Python: how to use each line at a time from array in requests

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

2 answers

  • answered 2022-05-04 10:55 mteam88

    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.

  • answered 2022-05-04 10:55 mak47

    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.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum