python use each line in for pool probleme
Question: i'm programming a script that fetch the http response and searching for 200
responses i need to make url like this : <http://exemple.com/string+number>
like : <http://exemple.com/hello123> hello string is in sites.txt and some
other strings , and i want to check them all with this 3 case numbers from 100
to 999 and this is the code : ok i will explain the code :) import urllib2

    
    
    import string
    #declaring the range of my pool
        def my_range(start, end, step):
            while start <= end:
                yield start
                start += step
    
        # open the file that contains the strings
        s = open("sites.txt","r+")
        # effect a value for url 
        url = 'http://exemple.com/'
        # initialize y to 100 cause i only need string+(100,999)
        y = 100
        # for pool to read the lines line by line
        for line in s.readlines():
        #initialize the y variable so it wont keep increasing by 1
         y = 100
         # effecting the line value to site so i can use it in the 2nd for pool
         site = line
         for x in my_range(100, 999, 1):
          url+=str(site)
          #increasing y by 1 to explore all the range (100,900)
          y =y+1
          #url = url+site+y like http://exemple.com/hello123
          url+=str(y)
          #checking wich url i reach it 
          print url 
          #all this to get a 200 response 
          req = urllib2.Request(url)
          try:
            resp = urllib2.urlopen(req)
          except urllib2.URLError, e:
            if e.code == 404:
                pass
            else:
                pass
          else:
            print "200"
            #initializing the url so it wont going like this http://exemple.com/hello123hello123hello123
          url = 'http://exemple.com/'
        body = resp.read()
    

the problem the script get only the first string in the txt file and the file
is by lines like this string1 string2 string3 string4 ... i'm a beginner with
python so some explanation or rewrite on the code could be very helpful thanks
for any help guys :)


Answer: You make multiple requests and get a response from each, but you only `read`
from the last one, because that is outside the loop.

